[.96] Not a bug : Both scripts should work equally

Forum rules
Please don't bump threads here if you have a problem - it will often be forgotten about if you do. Instead, make a new thread here.

Post a reply

Smilies
:D :) :( :o :shock: :? 8-) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :wink: :geek: :ugeek: :!: :?: :idea: :arrow: :| :mrgreen: :3: :wub: >:( :blergh:
View more smilies

BBCode is OFF
Smilies are ON

Topic review
   

Expand view Topic review: [.96] Not a bug : Both scripts should work equally

by Graf Zahl » Sun Jun 12, 2005 2:05 am

That works as well.

by Bio Hazard » Sat Jun 11, 2005 7:25 pm

why not just

Code: Select all

#include "zcommon.acs"

int i=0;
script 255 (void){
	if(i<3){
		GiveInventory("HealthBonus",5);
		if(i==0){Print(s:"You got a snack!");}
		else{Print(s:"You got another snack!");}
		i++;
	}else{Print(s:"They ran out!");}
}
?

by Graf Zahl » Sat Jun 11, 2005 6:28 am

Because the queued scripts are executed in reverse order, as I said.

if (i>=3)... first, then
if (i==2), then
if (i==1), then
if (i==0)

And logically then these side effects won't show.

by Costja » Sat Jun 11, 2005 6:13 am

Thanks for explanation of ACS_Execute special.

These scripts aren't my (they are from this thread). I simply didn't understand why second script "works".

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.

[.96] Not a bug : Both scripts should work equally

by Costja » Sat Jun 11, 2005 5:58 am

Both of this scripts should work equally (because they don't contain async statements), but the first script gives you 15 health points and the second script gives you 5 health point.
Spoiler: script 1
Spoiler: script 2

Top