Gamestudio Links
Zorro Links
Newest Posts
Data from CSV not parsed correctly
by EternallyCurious. 04/18/24 10:45
StartWeek not working as it should
by Zheka. 04/18/24 10:11
folder management functions
by VoroneTZ. 04/17/24 06:52
lookback setting performance issue
by 7th_zorro. 04/16/24 03:08
zorro 64bit command line support
by 7th_zorro. 04/15/24 09:36
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:48
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:46
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
3 registered members (Quad, VoroneTZ, 1 invisible), 648 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
EternallyCurious, 11honza11, ccorrea, sakolin, rajesh7827
19046 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 2 of 5 1 2 3 4 5
Re: trigger switch [Re: mschoenhals] #455367
10/17/15 21:05
10/17/15 21:05
Joined: Aug 2013
Posts: 101
M
mschoenhals Offline OP
Member
mschoenhals  Offline OP
Member
M

Joined: Aug 2013
Posts: 101
Looking at the code further (thank you so much by the way):
I see that active_tri has three states: 0, 1, 2, 3. However, my switch only has three positions (middle, up, down). My plan is that each of those three states will lead to a different position for doors/platforms. Do I really need the 4th state then?

Re: trigger switch [Re: mschoenhals] #455368
10/17/15 21:28
10/17/15 21:28
Joined: Feb 2012
Posts: 371
Dico Offline
Senior Member
Dico  Offline
Senior Member

Joined: Feb 2012
Posts: 371
the method of active_tri like this :

when you hit enter and active_tri = 0 then the variable turn to 1 (active_tri = 1)

and if active_tri = 1 your model should play "on" animation and when he fenish it he turn the var active_tri to 2.

and if the variable active_tri = 2 and you hit enter the active_tri turn to 3 so its play animation "off" and when he finish it , it turn variable active_tri to 0 so its the begining.

Re: trigger switch [Re: Dico] #455370
10/17/15 23:08
10/17/15 23:08
Joined: Aug 2013
Posts: 101
M
mschoenhals Offline OP
Member
mschoenhals  Offline OP
Member
M

Joined: Aug 2013
Posts: 101
So right now, I hit enter and the switch moves to the down position. When I hit enter again, nothing happens. hit it again, and it moves up. After that, it stops working all together.

I'm curious about the trig_percentage check in the while statement. Why is that used?

Code:
action trigger_switch()
{
	t_trigger = me; //this is a pointer defining the entity listed at the top
	var active_tri = 0;

	while(1)
	{
		if (key_enter)
		{
			if(active_tri == 0)  //this is the initial state of the trigger (middle)
			{
				active_tri = 1;  //position for up
			}
			if(active_tri == 1)
			{
				active_tri = 2;  //postion for down
			}
			if(active_tri == 2)
			{
				active_tri = 1;
			}
		}
		if(active_tri == 1)
		{
			while(trig_percentage > 0)
			{
				//			trig_percentage %= 100;
				trig_percentage += 2*time_step;
				ent_animate(t_trigger, "on", trig_percentage, ANM_SKIP);
				wait(1);
				//			trig_percentage = 0;
			}
			while(trig_percentage < 100)
			{
				//			trig_percentage %= 100;
				trig_percentage += 2*time_step;
				ent_animate(t_trigger, "off", trig_percentage, ANM_SKIP);
				wait(1);
				//			trig_percentage = 1;
			}
			active_tri = 2;
		}
		if (active_tri == 2)
		{
			while(trig_percentage > 0)
			{
				//			trig_percentage %= 100;
				trig_percentage += 2*time_step;
				ent_animate(t_trigger, "on", trig_percentage, ANM_SKIP);
				wait(1);
				//			trig_percentage = 0;
			}
			while(trig_percentage < 100)
			{
				//			trig_percentage %= 100;
				trig_percentage += 2*time_step;
				ent_animate(t_trigger, "off", trig_percentage, ANM_SKIP);
				wait(1);
				//			trig_percentage = 1;
			}
			active_tri = 1;
		}
		wait(1);
	}

}


Re: trigger switch [Re: mschoenhals] #455371
10/17/15 23:17
10/17/15 23:17
Joined: Feb 2012
Posts: 371
Dico Offline
Senior Member
Dico  Offline
Senior Member

Joined: Feb 2012
Posts: 371
remove this
Code:
if(active_tri == 2)
{
    active_tri = 1;
}



the code it work without it for up and down animation .
but i want to ask you. what do you want to do with this function ?

Re: trigger switch [Re: Dico] #455372
10/17/15 23:54
10/17/15 23:54
Joined: Aug 2013
Posts: 101
M
mschoenhals Offline OP
Member
mschoenhals  Offline OP
Member
M

Joined: Aug 2013
Posts: 101
Ultimately I want to use it so when the player hits it, it will rotate door(s) one way and when hit again, it rotates the other way. I'm slowly working towards that.

This is also helping me learn how to code. I'm a work in progress. laugh

Right now the switch will move down when I hit enter but then it moves up on it's own and stays there.

I'd like to learn how to debug better. I tried to take the variable active_tri out of the action and list it at the top of the screen so I could follow it in SED watch but the value never changes. Am I missing something?

Re: trigger switch [Re: mschoenhals] #455392
10/18/15 23:30
10/18/15 23:30
Joined: Aug 2013
Posts: 101
M
mschoenhals Offline OP
Member
mschoenhals  Offline OP
Member
M

Joined: Aug 2013
Posts: 101
Hi all,
Still working on my trigger switch behavior. I'm really trying to simplify it (to better understand what I'm doing) and also to learn how to debug it.

Right now I can hit enter and the level will move up but when I hit enter again, nothing happens. I have used the watch window and can see that the active_tri variable moves from 0 to 1 but that's where it stops.

Any ideas?

Code:
///////////////////////////////
#include <acknex.h>
#include <default.c>
///////////////////////////////

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

ENTITY* t_trigger;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

var trig_percentage;
var active_tri = 0;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

action trigger_switch()
{
	t_trigger = me; //this is a pointer defining the entity listed at the top

	while(1)
	{
		if (key_enter)
		{
			if(active_tri == 0)
			{
				while(1)
				{
					trig_percentage += 2*time_step;
					ent_animate(t_trigger, "on", trig_percentage, ANM_SKIP);
					active_tri = 1;
					wait(1);
				}

			}

			if (active_tri == 1)
			{
				while(1)
				{
					trig_percentage += 2*time_step;
					ent_animate(t_trigger, "off", trig_percentage, ANM_SKIP);
					active_tri = 0;
					wait(1);
				}
			}
		}
		wait(1);
	}
}

function main()
{
	level_load ("switch.wmb");
	wait(2);
	vec_set(camera.x, vector(-250, 0, 15));
}


Re: trigger switch [Re: mschoenhals] #455393
10/18/15 23:41
10/18/15 23:41
Joined: Feb 2012
Posts: 371
Dico Offline
Senior Member
Dico  Offline
Senior Member

Joined: Feb 2012
Posts: 371
because you have an infinite loop here :
Code:
while(1)
				{
					trig_percentage += 2*time_step;
					ent_animate(t_trigger, "on", trig_percentage, ANM_SKIP);
					active_tri = 1;
					wait(1);
				}


Re: trigger switch [Re: Dico] #455394
10/18/15 23:44
10/18/15 23:44
Joined: Feb 2012
Posts: 371
Dico Offline
Senior Member
Dico  Offline
Senior Member

Joined: Feb 2012
Posts: 371
correct code :

Code:
action trigger_switch()
{
	t_trigger = me; //this is a pointer defining the entity listed at the top

	while(1)
	{
		if (key_enter)
		{
			if(active_tri == 0)
			{
				trig_percentage = 0;
				while(trig_percentage < 100)
				{
					trig_percentage += 2*time_step;
					ent_animate(t_trigger, "on", trig_percentage, ANM_CYCLE);
					wait(1);
				}
				active_tri = 1;				
			}
			else
			{
				trig_percentage = 0;
				while(trig_percentage < 100)
				{
					trig_percentage += 2*time_step;
					ent_animate(t_trigger, "off", trig_percentage, ANM_CYCLE);
					wait(1);
				}		
				active_tri = 0;
			}
		}
		wait(1);
	}
}


Re: trigger switch [Re: Dico] #455424
10/19/15 16:52
10/19/15 16:52
Joined: Aug 2013
Posts: 101
M
mschoenhals Offline OP
Member
mschoenhals  Offline OP
Member
M

Joined: Aug 2013
Posts: 101
Ok, that works!
Thanks very much Dico. I'm off to try the next step in this code: trigger only when the player is near.

Thanks again.

Re: trigger switch [Re: mschoenhals] #455427
10/19/15 17:48
10/19/15 17:48
Joined: Aug 2013
Posts: 101
M
mschoenhals Offline OP
Member
mschoenhals  Offline OP
Member
M

Joined: Aug 2013
Posts: 101
I've now got my trigger system so it detects the player and will only active if the player is near and hits enter. What I want to do now is so when the switch is triggered in one direction, a platform or door moves one way and when the switch is hit again, it moves another way. Therefore I'm going to need a new action that is applied to the door/platform and a way of identifying which switch triggers what door/platform. That's likely going to be a skill defined when adding the door/platform behavior. Any ideas on where to start?

Here's my code so far:

Code:
ENTITY* t_switch;

var trig_percentage;
var t_switch_range = 150;

action trigger_switch()
{
	while (!player) {wait (1);} // wait until the player is loaded
	vec_set (my.skill61, my.x); // store the xyz initial position of the switch inside skill61... 63
	t_trigger = me; //this is a pointer defining the entity listed at the top
	var active_tri = 0; //variable defining where the switch is currently at.

	while(1)
	{
		c_scan(my.x, my.pan, vector(360, 180, t_switch_range), IGNORE_ME | SCAN_ENTS); // each switch scans around it, trying to detect the player
		if (you) // detected an entity?
		{
			if (you == player) // and that entity is the player?
			{
				if (key_enter)
				{
					if(active_tri == 0)
					{
						trig_percentage =0;
						while(trig_percentage < 100)  //stops an infinite loop. 
						{
							trig_percentage += 2*time_step;
							ent_animate(t_switch, "on", trig_percentage, ANM_SKIP);
							wait(1);
						}
						active_tri = 1;

					}

					else
					{
						trig_percentage = 0;
						while(trig_percentage < 100)  //stops an infinite loop. 
						{
							trig_percentage += 2*time_step;
							ent_animate(t_switch, "off", trig_percentage, ANM_SKIP);
							wait(1);
						}
						active_tri = 0;
					}
				}
			}
		}
		wait(1);
	}
}


Page 2 of 5 1 2 3 4 5

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1