Gamestudio Links
Zorro Links
Newest Posts
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
M1 Oversampling
by 11honza11. 04/30/24 08:16
Trading Journey
by howardR. 04/28/24 09:55
Zorro Trader GPT
by TipmyPip. 04/27/24 13:50
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
Why Zorro supports up to 72 cores?
by jcl. 04/26/24 11:09
Eigenwerbung
by jcl. 04/26/24 11:08
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (degenerate_762, AndrewAMD), 877 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
wandaluciaia, Mega_Rod, EternallyCurious, howardR, 11honza11
19049 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 5 1 2 3 4 5
trigger switch #455312
10/16/15 19:09
10/16/15 19:09
Joined: Aug 2013
Posts: 101
M
mschoenhals Offline OP
Member
mschoenhals  Offline OP
Member
M

Joined: Aug 2013
Posts: 101
Hi all,

Super-Noob here... shocked

I'm trying to animate a switch moving into the top position. I've got a frame called "top" on the Model in MED (only 1 frame - top1).

My code keeps returning a 1515 error. It has to do with my animation line. How do I fix this?

Code:
ENTITY* t_trigger;

function turn_on()
{
	var trig_percentage =0;
	
	while(1)
	{
		trig_percentage %= 100;
		trig_percentage += 2*time_step;
		ent_animate(me, "top", trig_percentage, ANM_SKIP);
		wait(1);
	}
}

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


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

Joined: Feb 2012
Posts: 371
Try this


Code:
var trig_percentage = 0;

function turn_on()
{
 trig_percentage = 1;

}

action trigger_switch()
{
	t_trigger=me; //this is a pointer defining the entity listed at the top
	on_enter = turn_on;
        while(1)
	{
            If(trig_percentage)
           {
		trig_percentage %= 100;
		trig_percentage += 2*time_step;
		ent_animate(me, "top", trig_percentage, ANM_SKIP);
           }
		wait(1);
	}


}


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

Joined: Aug 2013
Posts: 101
that totally worked; thanks. laugh
I guess I shouldn't have put the animation under the function? It should have stayed with the action?

Re: trigger switch [Re: mschoenhals] #455350
10/17/15 10:26
10/17/15 10:26
Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
Kartoffel Offline
Expert
Kartoffel  Offline
Expert

Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
The problem is the 'me' you've used in your turn_on-function.
Maybe this was done by mistake since you already created an entity-pointer and set it properly ('t_trigger').

However, you still used me in ent_animate() but the me-pointer is invalid here because it's a different function than the entities' action.

Replacing the 'me' with 't_trigger' should do the trick aswell.


POTATO-MAN saves the day! - Random
Re: trigger switch [Re: Kartoffel] #455359
10/17/15 18:58
10/17/15 18:58
Joined: Aug 2013
Posts: 101
M
mschoenhals Offline OP
Member
mschoenhals  Offline OP
Member
M

Joined: Aug 2013
Posts: 101
Ok, so my latest version of the trigger is an action that changes the switch from off to on everytime the player kits "enter". Unfortunately, I get just a black screen now. Here's the code:

Code:
ENTITY* t_trigger;

var trig_percentage;

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

	while(1)
	if (key_enter)
	{

		if(trig_percentage = 1)
		{
			trig_percentage %= 100;
			trig_percentage += 2*time_step;
			ent_animate(t_trigger, "on", trig_percentage, ANM_SKIP);
			trig_percentage = 0;
		}
		else
		trig_percentage %= 100;
		trig_percentage += 2*time_step;
		ent_animate(t_trigger, "off", trig_percentage, ANM_SKIP);
		trig_percentage = 1;
		
		wait(1);

	}


}


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

Joined: Feb 2012
Posts: 371
try this :
Code:
ENTITY* t_trigger;

var trig_percentage;

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

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

}



the wait function must be in while else your engine window will freeze

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

Joined: Aug 2013
Posts: 101
Yeah, that's what I thought but I'm such a total noob (just finished the workshop tutorials) that I don't know where to place it.

Re: trigger switch [Re: mschoenhals] #455363
10/17/15 20:03
10/17/15 20:03
Joined: Aug 2013
Posts: 101
M
mschoenhals Offline OP
Member
mschoenhals  Offline OP
Member
M

Joined: Aug 2013
Posts: 101
Ok, that totally worked. Except I was hoping that each time the enter button is hit, the switch would move to the opposite direction (on or off). I've added another if statement and included and else one too but the switch only moves to the "on" position and that's the end of it.
Code:
action trigger_switch()
{
	t_trigger = me; //this is a pointer defining the entity listed at the top

	while(1)
	{
		if (key_enter)
		{

			if(trig_percentage = 1)
			{
				trig_percentage %= 100;
				trig_percentage += 2*time_step;
				ent_animate(t_trigger, "on", trig_percentage, ANM_SKIP);
				trig_percentage = 0;
			}
			if(trig_percentage = 0)
			{
				trig_percentage %= 100;
				trig_percentage += 2*time_step;
				ent_animate(t_trigger, "off", trig_percentage, ANM_SKIP);
				trig_percentage = 1;
			}
			else
			{
				trig_percentage %= 100;
				trig_percentage += 2*time_step;
				ent_animate(t_trigger, "on", trig_percentage, ANM_SKIP);
				trig_percentage = 0;
			}
		}
		wait(1);
	}

}


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

Joined: Feb 2012
Posts: 371
Try this

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)
			{
				active_tri = 1;
			}
			if(active_tri == 2)
			{
				active_tri = 3;
			}
		}			
		if (active_tri == 1)
		{
			while(trig_percentage > 0)
			{
				trig_percentage -= 2*time_step;
				ent_animate(t_trigger, "off", trig_percentage, ANM_CYCLE);
				wait(1);
			}
			while(trig_percentage < 100)
			{
				trig_percentage += 2*time_step;
				ent_animate(t_trigger, "on", trig_percentage, ANM_CYCLE);
				wait(1);
			}
			active_tri = 2;
		}
		
		if (active_tri == 3)
		{
			while(trig_percentage > 0)
			{
				trig_percentage -= 2*time_step;
				ent_animate(t_trigger, "on", trig_percentage, ANM_CYCLE);
				wait(1);
			}
			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] #455366
10/17/15 20:58
10/17/15 20:58
Joined: Aug 2013
Posts: 101
M
mschoenhals Offline OP
Member
mschoenhals  Offline OP
Member
M

Joined: Aug 2013
Posts: 101
Ok, it went a step further now - the switch will go to off (down), then on (up) but stops there.

I was thinking about the variable active_tri; should I have a statement for when it equals 0?

Page 1 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