[Discussion] Generic X3TC S&M questions III

The place to discuss scripting and game modifications for X³: Terran Conflict and X³: Albion Prelude.

Moderators: Moderators for English X Forum, Scripting / Modding Moderators

Post Reply
User avatar
EmperorJon
Posts: 9378
Joined: Mon, 29. Dec 08, 20:58
x3tc

Post by EmperorJon » Fri, 22. Apr 11, 22:35

Quick question regarding object types and such... is there any way to get one converting from a string?

EG. The player types in Mammoth and I can spawn a Mammoth or say "This is not a recognised object", without me having to harcode the entire thing? As far as I can see... it's not possible... :(
______
I'm Jon. I'm mostly not around any more. If you want to talk, please message me! It's cool.
______

mark_a_condren
Posts: 1468
Joined: Wed, 3. Aug 05, 05:05
x3tc

Post by mark_a_condren » Sat, 23. Apr 11, 08:02

Yes, but it's a workaround (as usual).

Get input string, say Mammoth, then cycle through all the object types and do a temp convert object type to string and check that string for match against the input string. Wollah, create object type Mammoth, or send back to player "This is not a recognised object" if no match found.


MarCon

User avatar
EmperorJon
Posts: 9378
Joined: Mon, 29. Dec 08, 20:58
x3tc

Post by EmperorJon » Sat, 23. Apr 11, 09:06

I thought it'd come to that. Doesn't seem that bad actually.


I'm working on a fleet creator that can be used to create a fleet in game and out of game. You can type it directly into the T file, or it exports into a log file and then you can move it in. Should be, er... 'fun'.
______
I'm Jon. I'm mostly not around any more. If you want to talk, please message me! It's cool.
______

User avatar
s9ilent
Posts: 2033
Joined: Wed, 29. Jun 05, 01:45
x4

Post by s9ilent » Sat, 23. Apr 11, 14:39

*omg* l3+ ideas is temporarily closed :O

In any case, I'm posting this here (next best thing) as I will probably forget if I dont.


Idea: Provide better debug support, i.e. Instead of just debug log, and debug trace, provide the ability to put break points in scripts, and have a level of debug between log and trace (i.e. debug break- where it will only stop at the pre defined break points).
As often you want to debug after loops, but don't care about the loop it self (or any intermediate scripts that you call)

User avatar
EmperorJon
Posts: 9378
Joined: Mon, 29. Dec 08, 20:58
x3tc

Post by EmperorJon » Sat, 23. Apr 11, 21:54

I can't remember, but you could remove the ware and make it in a crate outside.


Now, a head scratching problem for me... :S



I have a fleet. It is stored in an array, as ship names and numbers and such.

Now, I want to have an array for each of those (groups of) ships. This stores equipment.

The problem I have is this... dynamically creating the arrays for ship equipment. None of this is saved in GVs or anything, it's all kept in a big open menu. It's only there when the menu is open. So... once I try to equip ship 1, I need an array called, say Equip1. Then for ship 2, Equip2, etc.

Short of making the arrays a global variable (and removing them on closing), I can't think there's another way of doing it... any help?
______
I'm Jon. I'm mostly not around any more. If you want to talk, please message me! It's cool.
______

User avatar
ScRaT_GER
Posts: 1962
Joined: Tue, 8. Jan 08, 18:19
x3tc

Post by ScRaT_GER » Sat, 23. Apr 11, 22:25

It's only there when the menu is open. So... once I try to equip ship 1, I need an array called, say Equip1. Then for ship 2, Equip2, etc.
Does that mean, that you only want to create the equipment array, if you actually try to equip that ship?

In any case, why not simply create an array of arrays:

Code: Select all

$ships = ... (your ships, array stays the same as long as the script runs)
$equipments = array alloc: size=$sizeOfShipArray

$selectedShip = ... (a ship you selected in the menu)
$index = get index of $selectedShip in $ships
$equipment = $equipments[$index]
if not $equipment
  * build $equipment array 
  $equipments[$index] = $equipment
end
* do something with $equipment
Like that, you'd lazily construct the array $equipments, which holds the equipment of each ship in the corresponding index.

Greetings,
ScRaT

User avatar
EmperorJon
Posts: 9378
Joined: Mon, 29. Dec 08, 20:58
x3tc

Post by EmperorJon » Sat, 23. Apr 11, 23:21

Yeah, but the point is, there are multiple ship groups... er, I'll try an example.


10 Nova
3 Centaur
2 Cerberus

All ships have shields, weapons etc...


So I create an array, equipment1, and match it up to the 10 Nova... but then, with the Centaurs, I need a new array, equipment2, and then 3 for cerberus, and an infinite number more for more ships...
______
I'm Jon. I'm mostly not around any more. If you want to talk, please message me! It's cool.
______

User avatar
ScRaT_GER
Posts: 1962
Joined: Tue, 8. Jan 08, 18:19
x3tc

Post by ScRaT_GER » Sun, 24. Apr 11, 00:19

Yeah, but the point is, there are multiple ship groups...
Then, instead of doing it on a per ship basis, do it on a per group basis. Where exactly is the problem with possibly infinite numbers of groups?

Maybe you could show some code, so that the problem gets clearer.

Greetings,
ScRaT[/quote]

User avatar
EmperorJon
Posts: 9378
Joined: Mon, 29. Dec 08, 20:58
x3tc

Post by EmperorJon » Sun, 24. Apr 11, 09:45

It is on a per group or per ship basis. (There may be a group of only 1 ship, for example)

The problem stems from the fact that, when setting up an array, I'm creating an array called Equipment, for example, every time, and cannot think of a way of setting up an array with a different name. I cannot think how to dynamically make a new array for every group there is.


Showing code is a last resort. I was tired when I did it. And, well, it's horribly inefficient and... messy.
______
I'm Jon. I'm mostly not around any more. If you want to talk, please message me! It's cool.
______

User avatar
ScRaT_GER
Posts: 1962
Joined: Tue, 8. Jan 08, 18:19
x3tc

Post by ScRaT_GER » Sun, 24. Apr 11, 10:40

I cannot think how to dynamically make a new array for every group there is.
The point is, that you cannot assign each equipment-array to a different variable, because you cannot create variables on the fly. So instead, you have to gather each equipment array in another array (as I did in the code below), so that you can later get them through their index in the array.

The code might look like this:

Code: Select all

$groups = ... (array of groups, where each group is an array of ships)
$size = size of array $groups
$equipments = array alloc: size=$size

* Fill $equipments array
$i = size of array $groups
while $i 
  dec $i =  
  = wait 1 ms
  $equipment = ... (somehow create an equipment array for that group)
  $equipments[$i] = $equipment
end
Now, you can get the equipment of each group, by getting their index in the $groups array and then using that index for the $equipments array.

This solution would be quite expensive though, because it would create the entire $equipments array directly. But depending on your menu, you don't even need that, which is why I proposed building the array lazily as you need the entries (see previous example).

Greetings,
ScRaT

User avatar
EmperorJon
Posts: 9378
Joined: Mon, 29. Dec 08, 20:58
x3tc

Post by EmperorJon » Sun, 24. Apr 11, 10:44

Ah, now I understand, thank you... Shame that MSCI doesn't support an easy 2D array function...
______
I'm Jon. I'm mostly not around any more. If you want to talk, please message me! It's cool.
______

User avatar
ScRaT_GER
Posts: 1962
Joined: Tue, 8. Jan 08, 18:19
x3tc

Post by ScRaT_GER » Sun, 24. Apr 11, 11:12

Shame that MSCI doesn't support an easy 2D array function...
What do you mean? You cannot create a 2D array directly, but at least you can get elements from a 2D array via $array[x][y].

Greetings,
ScRaT

User avatar
s9ilent
Posts: 2033
Joined: Wed, 29. Jun 05, 01:45
x4

Post by s9ilent » Sun, 24. Apr 11, 23:30

@EJ

Just some ideas for your fleet idea thingy. (Separation of concerns)

-Consider separating ship equipment, and ship types/numbers. e.g. Have some pre set ship "templates". As I'm guessing most of the time, each ship of the same type has a similar load out.
-Also you may want to just have an option to "max out shields=true" and not specify the shield type/qty directly. (assume this is always true, unless specified to be false?)

-Or pherhaps, you can have "hardpoint" load outs (turret/cockpit weapon combo's). And then you just specify what ship, and what loadout in which turret.



And finally w.r.t tfile/logfile
There's a json and an xml script lib in the stickies
Although tbh, it is probably easier to just write your own system from scratch.

NicoPalazzari
Posts: 66
Joined: Fri, 5. Mar 10, 20:24
x3tc

Post by NicoPalazzari » Mon, 25. Apr 11, 21:22

I updated my game to 3.1 and downloaded some of your scripts. The problem I'm having is that when I save my game it saves as 2.0 not 3.1. Is this caused by the scripts? I usually would not care, but the new marine aspects in later patches would be nice to have.

User avatar
X2-Illuminatus
Moderator (Deutsch)
Moderator (Deutsch)
Posts: 24965
Joined: Sun, 2. Apr 06, 16:38
x4

Post by X2-Illuminatus » Tue, 26. Apr 11, 09:32

I updated my game to 3.1 and downloaded some of your scripts.
It would help, if you would post in the scripts' topics or if you would say, which scripts you're using. This is a topic for general S&M questions, so it's not clear which scripts you refer to.
The problem I'm having is that when I save my game it saves as 2.0 not 3.1. Is this caused by the scripts?
No, scripts cannot change the game version. More probably you made a mistake while patching. Best you uninstall your scripts, download the 1.0 -> 3.0 and the 3.0 -> 3.1 patches again and install them after each other. Then check, if saving works without problems.
Nun verfügbar! X3: Farnham's Legacy - Ein neues Kapitel für einen alten Favoriten

Die komplette X-Roman-Reihe jetzt als Kindle E-Books! (Farnhams Legende, Nopileos, X3: Yoshiko, X3: Hüter der Tore, X3: Wächter der Erde)

Neuauflage der fünf X-Romane als Taschenbuch

The official X-novels Farnham's Legend, Nopileos, X3: Yoshiko as Kindle e-books!

sTeeL86
Posts: 28
Joined: Wed, 27. Apr 11, 06:48
x4

Post by sTeeL86 » Wed, 27. Apr 11, 09:02

Is MARS gonna cause problems with SRM/CMO4.8/IR install?

HotSake
Posts: 472
Joined: Sun, 3. Jan 10, 22:15
x3tc

Post by HotSake » Wed, 27. Apr 11, 15:23

sTeeL86 wrote:Is MARS gonna cause problems with SRM/CMO4.8/IR install?
This should be asked in the MARS thread, and no.

SyncViews
Posts: 58
Joined: Thu, 27. Jan 11, 14:38
x3tc

Post by SyncViews » Fri, 29. Apr 11, 11:56

Been working on adding menu interfaces and stuff to some of my scripts. Is there a way to simply display a message, with an OK button, kinda like the pause window, or what you get in Windows with MessageBox(mainWindow, "My Message", "Title", MB_OK)?

I tried doing somthing with custom menus but it always insists on creating the subheading things which I dont want, and send incoming message seems to never pop up over the command console :(

mark_a_condren
Posts: 1468
Joined: Wed, 3. Aug 05, 05:05
x3tc

Post by mark_a_condren » Fri, 29. Apr 11, 13:03

You could try,

$choice = THIS -> get user input: type=Var/Boolean, title='Select Yes to continue'

This will give you a 'Yes / No' dialog box with the 'Select Yes to continue' across the top.


MarCon

SyncViews
Posts: 58
Joined: Thu, 27. Jan 11, 14:38
x3tc

Post by SyncViews » Fri, 29. Apr 11, 13:14

hmm...I guess thats if the closest I can get. Just seems wrong for a "your asking the impossible" message...

Post Reply

Return to “X³: Terran Conflict / Albion Prelude - Scripts and Modding”