trigger_if_equal


(Ramm) #1

I am trying to make an elevator in ET with 1 button in the elevator itself. With a variable (accum 0) I look where the lift is (up/down). If it is down(0) then it should call the trigger move_up, else the trigger move_down. If I call the trigger move_up immediate it works, if I let him check wether the lift is up/down, it is not working. This is the code:


game_manager
{

}

move_platform
{
	trigger move_up
	{
		trigger lift movelift
	}
}

lift
{
	spawn
	{
		accum 0 set 0
		accum 1 set 0
		wait 200
	}

	trigger movelift
	{
		accum 0 trigger_if_equal 0 lift move_up
		accum 0 trigger_if_equal 1 lift move_down
	}

	trigger move_up
	{
	accum 1 set 1

	gotomarker level_016 600

	accum 1 set 0
	accum 0 set 1
	}

	trigger move_down
	{
	accum 1 set 1

	gotomarker level_001 600

	accum 0 set 0
	accum 1 set 0
	}
}

So probably the problem is situated here:


	trigger movelift
	{
		accum 0 trigger_if_equal 0 lift move_up
		accum 0 trigger_if_equal 1 lift move_down
	}

But I can’t see why he doesn’t execute the move_up or move_down


(EB) #2

Here is an elevator.zip for you to analyze.

Go to here:
http://www.spyjuice.com/tutorials_et.html
and get the: “Elevator_lift.zip”


(nUllSkillZ) #3

There’s a command to log the script actions (although not sure ATM what it’s name is).
And there is a possibility to print the accums and their values (although not sure how these commands are named).

Edit:

Something like “printaccum” I guess.


(C) #4

printaccum <accumNumber>
Prints the value in ‘accumNumber’ to the console.

printglobalaccum <accumNumber>
Prints the value in ‘accumNumber’ to the console.

I also find these commands very useful:

/con_drawnotify
This command allows developer commands such as r_speeds to display in the main game view and not just in the console. The command is toggled between 0 and 1 where 0 displays the developer commands in console only and 1 displays them in-game also.

/scriptdebug (/g_scriptdebug ?)
Prints to the server console every line of script that is executed, along with the scriptname of the entity which is calling the script, and the time it was executed at. This is extremely useful for tracking down strange script bugs.

/logfile 1


(BigBadWolf) #5

Ive never seen a script writen like this befor, so ill just try to rewrite the way i think you want it to work. By the way this is untested. Also, i couldnt see what accum 1 was for so i got rid of it.

Now, this code here is going to move the lift to the first path_corner, then move it right back, because it has nothing to cancel the second trigger (move_down)


game_manager 
{ 

} 

move_platform 
{ 
   trigger move_up 
   { 
	trigger lift movelift 
   } 
} 

lift 
{ 
   spawn 
   {
	wait 200
	accum 0 set 0 
   } 

   trigger movelift 
   { 
	trigger self move_up
	trigger self move_down
   } 

   trigger move_up 
   { 
	accum 0 abort_if_not_equal 0 
	gotomarker level_016 600 
	accum 0 set 1 
   } 

   trigger move_down 
   { 
	accum 0 abort_if_not_equal 1 
	gotomarker level_001 600 
	accum 0 set 0 
   } 
}

This one will toggle the lift to move to just the up position and stop, and press the button again to move it down, and vice versa. You have to have the target_script_trigger targeting the “start” command in the script.


movelift
{
	spawn
	{
		accum 1 set 0
	}

	trigger start //toggle control
	{
		trigger self up
		wait 5
		trigger self down
	}

	trigger up //moving lift up
	{
		accum 1 abort_if_not_equal 0
		resetscript
		accum 1 set 1
		trigger lift move_up

	}

	trigger down //moving lift down
	{
		accum 1 abort_if_not_equal 1
		resetscript
		accum 1 set 0
		trigger lift move_down

	}
}

lift
{
	spawn
	{
	}
	
	trigger move_up
	{
		gotomarker level_016 600
	}
	
	trigger move_down
	{
		gotomarker level_001 600
	}
}


(kamikazee) #6

@BigBadWolf: your first piece of code is indeed a rewrite of what happens with the first one.

Instead of your second part of code, you could keep the original code and rewrite only the things in the lift script block:

lift
{
	spawn
	{
		accum 0 set 0 // Lift position, 1 = UP here
		accum 1 set 0 // Lift moving flag, could be done using bitset
		wait 200
	}

	trigger movelift
	{
		accum 0 trigger_if_equal 0 lift move_up
		accum 0 trigger_if_equal 1 lift move_down
	}

	trigger move_up
	{
	accum 1 abort_if_equal 1
	accum 1 set 1

	gotomarker level_016 600 wait

	accum 1 set 0
	accum 0 set 1
	}

	trigger move_down
	{
	accum 1 abort_if_equal 1
	accum 1 set 1

	gotomarker level_001 600 wait

	accum 0 set 0
	accum 1 set 0
	}
}

Notice the wait parameter given to the gotomarker command. This makes the script wait till the animation is completed before executing the code after it, and the script will not return to the caller function like resetscript does. (I found out the hard way when I started scripting.)


(murka) #7

yes the best is to use wait after the animation. kinda depends on what u use it. but for lifts always wait after animation.
i do my lifts like this


trigger1
{
    spawn
    {
        globalaccum 1 set 0
    }

    trigger up
    {
         globalaccum 1 abort_if_equal 1
        trigger elevator up
    }
}

trigger2
{
    trigger down
    {
        globalaccum 1 abort_if_equal 0
        trigger elevator down
    }
}

elevator
{
    spawn
    {
        wait 300  //this is a MUST. u will recieve errors that the entity with the targetname, that the elevator is going to doesn't exist
        gotomarker floor1 50000
    }

    trigger up
    {
        gotomarker floor2 100 wait
        globalaccum 1 set 1
    }

    trigger down
    {
        gotomarker floor1 100 wait
        globalaccum 1 set0
    }
}


(BigBadWolf) #8

Oh.

Ive never seen trigger_if_equal, so i didnt think it would work. Havent tried it.


(murka) #9

me neither :evil: