by Graf Zahl » Sat Jun 11, 2005 6:06 am
The first script does exactly what is to be expected. The second, however, suffers from synchronization issues. ACS_Execute doesn't run the executed script itself. It just queues the script for execution in thew next tic. But AFAIK the last one queued is the first one executed so they are run in order 258, 257, 256, 255.
In the end both suffer from a simple programming error: What you want is probably:
Code: Select all
script 255 (void)
{
If(i == 0) {
GiveInventory("HealthBonus", 5);
Print(s: "You got a snack!");
i++;
}
else If(i == 1) {
GiveInventory("HealthBonus", 5);
Print(s: "You got another snack!");
i++;
}
else If(i == 2) {
GiveInventory("HealthBonus", 5);
Print(s: "You got another snack!");
i++;
}
else If(i >= 3) {
Print(s: "They ran out!");
}
}
Without the 'else's all if branches are executed.
The first script does exactly what is to be expected. The second, however, suffers from synchronization issues. ACS_Execute doesn't run the executed script itself. It just queues the script for execution in thew next tic. But AFAIK the last one queued is the first one executed so they are run in order 258, 257, 256, 255.
In the end both suffer from a simple programming error: What you want is probably:
[code]
script 255 (void)
{
If(i == 0) {
GiveInventory("HealthBonus", 5);
Print(s: "You got a snack!");
i++;
}
else If(i == 1) {
GiveInventory("HealthBonus", 5);
Print(s: "You got another snack!");
i++;
}
else If(i == 2) {
GiveInventory("HealthBonus", 5);
Print(s: "You got another snack!");
i++;
}
else If(i >= 3) {
Print(s: "They ran out!");
}
}[/code]
Without the 'else's all if branches are executed.