That ... example is probably less than helpful, especially since it's outright wrong.
Alright, so let's just get to the nitty gritty of your actual mistakes.
First, you need to understand a thing called [wiki]scope[/wiki]. There's more to it than this, but the basics of it is that a variable define in a script only exists to that script and any functions it calls, while a variable defined outside of any script exists for all of them. Or, to put it into actual code, this
Code: Select all
script 1 OPEN {
int a = 6;
}
script 2 ( void ) {
int b = a + 5;
}
will error out, because script 2 has no access to a variable called
a, while
Code: Select all
int a;
script 1 OPEN {
a = 6;
}
script 2 ( void ) {
int b = a + 5;
}
will compile, as a is in the proper scope for script 2 to access it.
Next, [wiki]operators[/wiki]. While your usage of the + operator is correct, that = is utter nonsense to ZDoom and ... every programming language I can think of. This is because it's specifically the variable to the
left side of the = operator is what gets set to whatever's on the
right side of it. Which means a + 1 = a is incorrect in that it's trying to set a non-variable to a value, but a = a + 1 is correct because it's setting a variable to a value. That said, ramon.dexter was correct that the ++ operator will work instead; in fact, that's its only purpose.
Finally, you'll need to take a moment to consider what you're doing. From what I can tell, you have actors set up so that they can call script 1 via their special ( which is executed when they're picked up if they're items, or when they die if they're monsters ), and then use script 2 to check if that values reaches a certain threshold. You've almost got the framework for that, but let's explain why via [wiki]script types[/wiki] real quick. script 1 has no type, while script 2 has the OPEN type - meaning that script 1 won't call itself on its own, while script 2 will do so when the map starts up. That said, that means it starts up, goes through its code, then ends - that's because scripts don't repeat by default, and you need something like [wiki]loops[/wiki] for something like that. In this situation, you'd want to set up a while loop, such as
Code: Select all
script 2 OPEN {
while( a < x ) {
Delay( 5 );
}
// place the rest of the code here
}
This is a script that runs at the start of the map, then immediately enters into a neverending loop until a is equal or greater than x ( or, rather, it continuously loops
while a is less than x - as the name implies, while loops don't stop until their condition is no longer met ). During this loop, the script does absolutely nothing aside from [wiki]delay[/wiki]ing itself from doing anything else, which is important because otherwise the loop would go on forever at infinite speed - or at least, it would if not for the fact that ZDoom cancels ACS infinite loops automatically by terminating the script, meaning that it'd instead cause the script to break instantly. Either way, you don't want to leave our a Delay() call in a loop that won't end itself without time passing. Anyway,
Once that condition is no long met, the while loop will automatically end, leading to the rest of the script - this is why we're using a while loop, as it allow us the basically park a script in place until that condition is met, then continue on where it left off without a hitch. Then, once it's done all that code, script 2 will automatically terminate - for the same reason that you don't need to put terminate in script 1.
One foreword: when and then don't exist in ACS, it's an C-based language. Instead, you have if statements, which are structured like this:
Code: Select all
script 1 void {
if( x == y ) { // the condition
// the stuff you want to put after "then" goes here
} // these curly braces are essential, though you can place them like this ...
if( x == z )
{
} // or like this; spacing and stuff is very flexible in acs, you just need to make sure that the right symbols follow the right symbols
else
{
// also, using the else statement, you run code should the if statement fail!
}
}