3 registered members (Quad, VoroneTZ, 1 invisible),
648
guests, and 2
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Re: trigger switch
[Re: Dico]
#455370
10/17/15 23:08
10/17/15 23:08
|
Joined: Aug 2013
Posts: 101
mschoenhals
OP
Member
|
OP
Member
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?
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
Senior Member
|
Senior Member
Joined: Feb 2012
Posts: 371
|
remove this
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
mschoenhals
OP
Member
|
OP
Member
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. 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
mschoenhals
OP
Member
|
OP
Member
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?
///////////////////////////////
#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]
#455427
10/19/15 17:48
10/19/15 17:48
|
Joined: Aug 2013
Posts: 101
mschoenhals
OP
Member
|
OP
Member
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:
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);
}
}
|
|
|
Moderated by mk_1, Perro, rayp, Realspawn, Rei_Ayanami, rvL_eXile, Spirit, Superku, Tobias, TSG_Torsten, VeT
|