So in the topic "Scripting functions" we spoke about the gosub commands, and I think most scripter's know how to use gosub's, but not many know that gosub's CAN be used as a condition, well, in-fact they can; and it's useful if you're making a long script with lots of memory hacking tricks.
But what is the trick? Are you starting to wonder now? Have I got your attention? Well then let us continue.
Well, using gosub in such way requires special design results in the script, you need to tell the script to return false if the result is NOT true, or if IS true then you need to return it TRUE. (0485: return_true or 059A: return_false).
If the gosub returned false, then so it jump to the label "__False" if it HAS returned true, then it continues where it says "result is true, continue..."
As you can see(?), it checks if the actor is a male, if he IS a male then it returns true, and this means the gosub IS true, if the actor is not a male, then it goes to the label "RetFalse" and returns false, BOTH codes end with a normal "return" command, this is of course so the script can go back to check if the gosub is TRUE or FALSE.
--
Sanny Builder supports storing a label name to a varible then jumping using that varible. For example:
Store it:
Then you can jump like this:
Like that:
Same trick apply's to gosubs, and jump_if_false
--
With just one condition there is no need at all for an if command, in-fact, it's better without it, as it's saving more space, if there IS more then one condition THEN if(AND/OR) is needed, but if you are only using one condition, then if can be omitted from the script, and you can leave it out.
If you declare the player or actor to the game engine using var..end, we can now do this kind of stuff:
The game knows that $PLAYER_CHAR means the player, so now all is necessary is the varible, then what your doing, like for example above I'm checking if the player is defined.
($2 is equal to $PLAYER_CHAR, and $3 is equal to $PLAYER_ACTOR, so you can use these instead of). When you decompile $2 will = $PLAYER_CHAR, and $3 = $PLAYER_ACTOR.
But what is the trick? Are you starting to wonder now? Have I got your attention? Well then let us continue.
Well, using gosub in such way requires special design results in the script, you need to tell the script to return false if the result is NOT true, or if IS true then you need to return it TRUE. (0485: return_true or 059A: return_false).
- Code:
if
gosub @Check_Type
jf @__False
// result is true, continue...
If the gosub returned false, then so it jump to the label "__False" if it HAS returned true, then it continues where it says "result is true, continue..."
- Code:
:Check_Type
if
03A3: actor 0@ is_male
jf @RetFalse
0485: return_true
return
:RetFalse
059A: return_false
return
As you can see(?), it checks if the actor is a male, if he IS a male then it returns true, and this means the gosub IS true, if the actor is not a male, then it goes to the label "RetFalse" and returns false, BOTH codes end with a normal "return" command, this is of course so the script can go back to check if the gosub is TRUE or FALSE.
--
Sanny Builder supports storing a label name to a varible then jumping using that varible. For example:
Store it:
- Code:
0@ = @Label
Then you can jump like this:
- Code:
jump 0@
Like that:
- Code:
:Script
if
1@ == 0
jf @Script1
0@ = @Script2
jump 0@
Script1
//.....
:Script2
Same trick apply's to gosubs, and jump_if_false
--
With just one condition there is no need at all for an if command, in-fact, it's better without it, as it's saving more space, if there IS more then one condition THEN if(AND/OR) is needed, but if you are only using one condition, then if can be omitted from the script, and you can leave it out.
- Code:
:Label
wait 0
0248: model #INFERNUS available
jf @Label
- Code:
var
$PLAYER_CHAR: Player
$PLAYER_ACTOR: Actor
end
If you declare the player or actor to the game engine using var..end, we can now do this kind of stuff:
- Code:
$PLAYER_CHAR.Defined
The game knows that $PLAYER_CHAR means the player, so now all is necessary is the varible, then what your doing, like for example above I'm checking if the player is defined.
($2 is equal to $PLAYER_CHAR, and $3 is equal to $PLAYER_ACTOR, so you can use these instead of). When you decompile $2 will = $PLAYER_CHAR, and $3 = $PLAYER_ACTOR.