Scripting mistake

eddieb

Vice Admiral
Hi all:

For your scripters, please note the following. The ship ids must be unique for the lifetime of the mission. It is not correct to do this

code=math.random(0,65536);
id="$" .. code;

and then use id as a ship id. It is also wrong to use the same id when creating multiple ships.

The correct thing to do is somewhere at initialization time do

code = 0;


then when you want to create your ship
id = id="$" .. code;

then go create a new ship, and after ship creation do

code = code + 1
 
Understood... It's my fault ;)
Only for curiosity, what kind of problems can give that way of coding?
 
Yes, the scriptids for ships must be unique. So just use a counter, not a random number generator.

In the old version of the engine, this would possibly cause scripted commands to go to the wrong ship. In the 1.4 beta, I check for this sort of bug, print an error message out, and don't execute the command.

Don't feel bad, I made this same mistake when I was doing my jump cutscenes, and found it really handy to see the new error messages.

I'm in the process of merging in venom's stuff, and then I'll private message you all when the beta is up.
 
Back
Top