2 registered members (ozgur, Quad),
880
guests, and 1
spider. |
Key:
Admin,
Global Mod,
Mod
|
|
|
trigger switch
#455312
10/16/15 19:09
10/16/15 19:09
|
Joined: Aug 2013
Posts: 101
mschoenhals
OP
Member
|
OP
Member
Joined: Aug 2013
Posts: 101
|
Hi all, Super-Noob here... 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?
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]
#455350
10/17/15 10:26
10/17/15 10:26
|
Joined: Jun 2009
Posts: 2,210 Bavaria, Germany
Kartoffel
Expert
|
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: mschoenhals]
#455360
10/17/15 19:06
10/17/15 19:06
|
Joined: Feb 2012
Posts: 371
Dico
Senior Member
|
Senior Member
Joined: Feb 2012
Posts: 371
|
try this :
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: mschoenhals]
#455363
10/17/15 20:03
10/17/15 20:03
|
Joined: Aug 2013
Posts: 101
mschoenhals
OP
Member
|
OP
Member
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.
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
Senior Member
|
Senior Member
Joined: Feb 2012
Posts: 371
|
Try this
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);
}
}
|
|
|
Moderated by mk_1, Perro, rayp, Realspawn, Rei_Ayanami, rvL_eXile, Spirit, Superku, Tobias, TSG_Torsten, VeT
|