Old Murgh wrote: ↑Sun Jul 24, 2022 1:54 pm
I see the possibility of interpreting multiple ships in two senses: One script I can apply to the whole entire shipset, or one script to apply to each core ship that can fork to multiple variants?
The switch allows you to make choices per ship data key. And it is the ship data keys you have in your shipdata.plist file where the condition script has been added.
If you want to apply something to all ship keys where the condition script is applied, then the switch is unnecessary. Just have the "if" statement and you're good to go.
If you want to keep the switch, then there are certain rules you need to follow.
A switch statement is structured like this:
Code: Select all
switch (thing_to_switch_on) { // "thing_to_switch_on" is the data element you want to base your switch on
case "type 1": // this is the first possible option
// ...code specific to type 1
break; // you must "break" out of the switch after executing switch code
case "type 2": // this is the second possible option
// ...code specific to type 2
break;
case "type 3": //
case "type 4": // we're combining these 2 options
// ...code specific to types 3 and 4
break;
default: // if none of the above were found, this is the "catch any other type" part of the switch
// .. code for any other type
break; // technically this isn't needed here, but it's useful for ease of understanding and consistency
}
In montana05's example, the "thing_to_switch_on" is the ship's data key (in the code, defined as "shipKey"). He has defined the switch for two ship keys, and the structure means the same code will apply to both.
Now, if you were to add this condition script to other ship keys in shipdata.plist, in it's current form, they would always be prevented from spawning, because the "default" part of the switch would come into effect, and that code always returns "false". If you wanted to use the same rules for the new ship as are used for "my_ship_01" and "my_ship_02", then you would just add that key immediately under the existing ones, like this:
Code: Select all
case "my_ship_01":
case "my_ship_02":
case "my_ship_03":
If, however, you wanted a different set of rules to apply, you'd need to define a new section in the switch, and put the rules in there.
For example:
Code: Select all
case "my_ship_03":
if (gov == 3 && tech < 4)
return true;
break;
Hopefully that helps a bit in understanding the code.