As this has become the de facto script thread, I thought I'd post another code example.
You are able to get your threads returning values.
So, for example, say you have a thread that moves a flag up/down a flagpole (if the player is holding down use and inside a region):
Code:
//-------------------------------------------------------------------------------//
// flag movement
// returns true or false depending on success of move
//
// move_flag [objective] [flag] [direction]
//-------------------------------------------------------------------------------//
move_flag local.objective local.flag local.direction:
local.FlagComplete = false //set flag state to not moved
local.distance = 0
local.player = parm.other //get player
local.zone = $(local.objective + "_zone") //get zone
local.flag loopsound tick_pulley
while ((isAlive local.player) && (local.player.useheld == 1) && (local.player isTouching local.zone))
{
local.flag time level.flag_speed //get speed of flag
if(local.direction == up)
local.flag moveUp level.flag_move_rate //move flag up once by a specified amount of units
else
local.flag moveDown level.flag_move_rate //move flag down once by a specified amount of units
local.flag waitmove //wait until moved
local.distance += level.flag_move_rate //add up distance moved
if (local.distance >= level.flag_pole_length)
{
local.FlagComplete = true //flag successfully moved
break //leave loop, it's completed!
}
}
local.flag stoploopsound tick_pulley
end local.FlagComplete
This will return a value of either 'true' or 'false' depending on the success of player. You can then grab the value as a variable in another thread:
Code:
local.FlagComplete = waitthread move_flag local.num local.flag down // move the flag
if !(local.FlagComplete == true) // interrupted, return the flag! (previous thread returned 'false')
{
local.player stopwatch 0 // kill stopwatch
local.time = waitthread get_return_duration local.flag1_time // calculate return duration
waitthread flag_return local.flag NIL local.up_pos NIL local.time
}