by HotWax » Fri Mar 12, 2004 1:37 am
It's not a bug, it's a misusage of ThingCount. From the wiki:
int ThingCount(int type, int tid);
You're trying to use a string for the type instead of an int. Due to that, you'll get unpredictable results.
Now you're probably asking why the hell the first one works but the second doesn't. To understand that, you have to understand that all strings in ACS are converted to numbers at compile time. The actual strings are then stored in a string table. For example, when the compiler processes your script, this is what gets put in the string table:
Code: Select all
String 0: "ArmorBonus"
String 1: "DeadDoomImp"
String 2: "RedCard"
String 3: "DeadMarine"
String 4: "Same script, different objects, what gives?"
String 5: "This is how it should behave"
In the actual code where the functions reference these strings, the compiler instead places a reference into the string table. For example, this:
Code: Select all
hudmessage (s: "Same script, different objects, what gives?"; HUDMSG_TYPEON | HUDMSG_LOG, 0, CR_WHITE, 0.5, 0.75, 0.0, 0.05, 2.0);
becomes this:
Code: Select all
hudmessage (s: 4; HUDMSG_TYPEON | HUDMSG_LOG, 0, CR_WHITE, 0.5, 0.75, 0.0, 0.05, 2.0);
Since ZDoom knows that it's looking for a string (due to the s: preceeding the number), it looks up string 4 and prints it to the screen, rather than simply printing "4". However, if ZDoom was expecting an int, it will use the actual number instead. Hence, this:
Code: Select all
while (thingcount ("ArmorBonus", x_tid))
becomes this:
Which works perfectly because 0 = T_NONE, or no mask. When all things with a TID of x_tid are gone, the while ends. As far as YOU see, it's working as intended. However, this line:
Code: Select all
while (thingcount ("RedCard", x_tid))
becomes this:
Now ZDoom is looking for a specific type of thing; in this case, a chaingunner. Since you don't have any chaingunners with a TID of x_tid, the result will always be 0 and the script will behave incorrectly.
Fixing the script in this instance should be easy. Just replace the first argument of each thingcount call to T_NONE. As long as you don't have any other things in the level that use the same TIDs, you should be set. If you absolutely need to specify the thing type, you can find the list in your zdefs.acs file. The ones you're looking for in this case are T_ARMORBONUS and T_REDKEYCARD.
It's not a bug, it's a misusage of ThingCount. From the wiki:
[quote]int ThingCount(int type, int tid);[/quote]
You're trying to use a string for the type instead of an int. Due to that, you'll get unpredictable results.
Now you're probably asking why the hell the first one works but the second doesn't. To understand that, you have to understand that all strings in ACS are converted to numbers at compile time. The actual strings are then stored in a string table. For example, when the compiler processes your script, this is what gets put in the string table:
[code]String 0: "ArmorBonus"
String 1: "DeadDoomImp"
String 2: "RedCard"
String 3: "DeadMarine"
String 4: "Same script, different objects, what gives?"
String 5: "This is how it should behave"[/code]
In the actual code where the functions reference these strings, the compiler instead places a reference into the string table. For example, this:
[code]hudmessage (s: "Same script, different objects, what gives?"; HUDMSG_TYPEON | HUDMSG_LOG, 0, CR_WHITE, 0.5, 0.75, 0.0, 0.05, 2.0);[/code]
becomes this:
[code]hudmessage (s: 4; HUDMSG_TYPEON | HUDMSG_LOG, 0, CR_WHITE, 0.5, 0.75, 0.0, 0.05, 2.0);[/code]
Since ZDoom knows that it's looking for a string (due to the s: preceeding the number), it looks up string 4 and prints it to the screen, rather than simply printing "4". However, if ZDoom was expecting an int, it will use the actual number instead. Hence, this:
[code]while (thingcount ("ArmorBonus", x_tid))[/code]
becomes this:
[code]while (thingcount (0, x_tid))[/code]
Which works perfectly because 0 = T_NONE, or no mask. When all things with a TID of x_tid are gone, the while ends. As far as YOU see, it's working as intended. However, this line:
[code]while (thingcount ("RedCard", x_tid))[/code]
becomes this:
[code]while (thingcount (2, x_tid))[/code]
Now ZDoom is looking for a specific type of thing; in this case, a chaingunner. Since you don't have any chaingunners with a TID of x_tid, the result will always be 0 and the script will behave incorrectly.
Fixing the script in this instance should be easy. Just replace the first argument of each thingcount call to T_NONE. As long as you don't have any other things in the level that use the same TIDs, you should be set. If you absolutely need to specify the thing type, you can find the list in your zdefs.acs file. The ones you're looking for in this case are T_ARMORBONUS and T_REDKEYCARD.