While in Trigger event

Posted By: Ayumi

While in Trigger event - 11/23/16 07:49

Hey,

i have tryed to set a while in TRIGGER_EVENT and wait for SHOW/Hide Panel.

The while should go through until 0 is reached but this only works with wait (-1);
If wait(1);, the while only runs once.

Why?

Code:
var pressed = 0;

action DsTrigger() 
{
	my.emask |= (ENABLE_TRIGGER);
	my.trigger_range = 222;	
	my.event = DsTriggered;
}		

void DsTriggered()
{
	if(event_type == EVENT_TRIGGER)
	{			
		RaiseDsTrigger();	
	}	
}

void RaiseDsTrigger()
{
	var dist = abs(vec_dist(player.x, my.x));
	if(dist < 244)
	{
		set(DsPanelE, SHOW);
		
		if(pressed == 0)
		{					
			pressed++;
			
			while(pressed > 0)
			{	
				if(key_pressed(18))
				{		
					if(pressed == 2)
					{
						wait(-1);
						reset(DsPanel, SHOW);
						pressed = 0;
					}	
					
					if(pressed == 1)
					{	
						reset(DsPanelE, SHOW);
						wait(-1);
						set(DsPanel, SHOW);	
						pressed++;			
					}
				}									
			
				wait(1);
			}			
		}		
	}	
	else
		reset(DsPanelE, SHOW);	
}

Posted By: 3run

Re: While in Trigger event - 11/23/16 10:58

I'll take a closer look at your code a bit later, but for now, maybe you'll make sure that your triggered event will run only once? At the beginning of your event function, just disable ENABLE_TRIGGER, and enable it right at the end, so it could be called once again.

Greets!
Posted By: Ayumi

Re: While in Trigger event - 11/23/16 11:21

Thanks for your response, but that not solve the problem.
Posted By: 3run

Re: While in Trigger event - 11/23/16 11:24

I tried to understand what you are trying to archive from your code, and wrote this:
Code:
#define RANGE 150

PANEL* DsPanel = {
	pos_x = 10;
	pos_y = 10;
	bmap = "paddle.pcx";
}

PANEL* DsPanelE = {
	pos_x = 200;
	pos_y = 10;
	bmap = "quad.tga";
}

void DsTriggered()
{
	if(event_type == EVENT_TRIGGER)
	{
		my.emask &= ~ENABLE_TRIGGER;
		
		var dist = abs(vec_dist(player.x, my.x));
		
		set(DsPanelE, SHOW);
		
		if(dist < RANGE)
		{
			var pressed = 1, counter = 1;
			
			while(pressed > 0){
				
				if(key_pressed(18)){
					if(pressed == 1){
						reset(DsPanelE, SHOW);
						while(counter > 0){
							counter -= time_frame / 16;
							if(vec_dist(player.x, my.x) > RANGE){ break; }
							wait(1);
						}
						set(DsPanel, SHOW);
						pressed = 2;
					}
					if(pressed == 2){
						counter = 1;
						while(counter > 0){
							counter -= time_frame / 16;
							if(vec_dist(player.x, my.x) > RANGE){ break; }
							wait(1);
						}
						reset(DsPanel, SHOW);
						pressed = 0;
					}
				}
				
				if(vec_dist(player.x, my.x) > RANGE){ break;}
				
				wait(1);	
			}
		}
		else{
			reset(DsPanelE, SHOW);	
		}
		
		while(abs(vec_dist(player.x, my.x)) < RANGE){ wait(1); }
		my.emask |= ENABLE_TRIGGER;
	}	
}

action DsTrigger() 
{
	my.emask |= ENABLE_TRIGGER;
	my.trigger_range = RANGE;	
	my.event = DsTriggered;
}

void main(){
	fps_max = 60;
	warn_level = 6;
	level_load("");
	wait(3);
	
	vec_set(sky_color.blue, COLOR_BLACK);
	
	player = ent_create(CUBE_MDL, nullvector, NULL);	
	ent_create(CUBE_MDL, vector(200, 0, 0), DsTrigger);	
	
	while(player){
		
		player.skill1 = 10 * (key_w - key_s) * time_step;
		player.skill2 = 10 * (key_a - key_d) * time_step;
		player.skill3 = 0;
		
		c_move(player, player.skill1, nullvector, IGNORE_PASSABLE | ACTIVATE_TRIGGER | GLIDE);
		
		vec_set(camera.x, player.x);
		vec_set(camera.pan, player.pan);
		
		wait(1);
	}
}

Give it a try, maybe it's something that you are looking for?

Edit: you may wanna add distance checks, so when player is out of the trigger range, you break all loops (ADDED INTO THE CODE).

Edit2: are you trying to archive somekind of a dialog thing? what are you trying to archive, maybe there is a better way to handle it. If you could tell us, then we might help you out laugh

Best regards!
Posted By: Ayumi

Re: While in Trigger event - 11/23/16 12:10

Ok i have tryed both, my and your code but same result.

Yes, i want a kind of dialog, just shown in trigger range but in genral without a permanent while loop.
Posted By: 3run

Re: While in Trigger event - 11/23/16 12:32

I'm afraid you won't be able to do this without while loop, since TRIGGER will be triggered each time you move (if you call ACTIVATE_TRIGGER in your c_move), so you'll have to disable ENABLE_TRIGGER as soon as you are going to display your first dialog. My example actually works, I tested it before posting here, it show DsPanelE panel as soon as you entered the trigger range. When you press E key, it will make DsPanelE invisible, will wait for 1 second and make DsPanel visible. After thatn if you keept on holding E key (or simply press it once again, since we are in main loop) it will make DsPanel invisible after once second and will exit the main loop (since pressed will equal to 0). Isn't that what you wanted to archive in your code example in your first post?

For dialogs I wouldn't use TRIGGER, cause imagine you'll have about 5 NPCs near each other, as soon as you'll get close to them, you'll trigger all their events, you could check for the distance, but still, it's not what I would like to archive. Instead, try something with interaction trace, so you will need to get close to each NPC, look at it and press E key (when you press E key, trace once to the offset position infront of the player/camera, with ACTIVATE_SHOOT f.e. so you could run ENABLE_SHOOT event for each NPC).

EDIT: or you can take a look at this example, I converted it from older Mirrowind tutorial from AUMs. Do exactly the same thing in TRIGGER event (if you need this trigger stuff so much), but don't forget to disable/enable TRIGGER events.
Dialogs

Greets!
Posted By: Ayumi

Re: While in Trigger event - 11/23/16 12:58

I am using A7 and your example dosn t work for me.

I would use trigger, because they arn t use a while anytime. Not just for Dialogs...any static.
If 2 or more NPCs are nearby, they are separated by numbers.

A7 has no regions:(


EDIT: remember, my code works with wait(-1); (but not wait(1-30..)
Posted By: 3run

Re: While in Trigger event - 11/23/16 15:48

It's strange that it doesn't work with A7... Since my solutions do not work for you, I step aside, sorry. Hopefully some one more experienced than me, will help you out.

Best regards.
Posted By: Ayumi

Re: While in Trigger event - 11/23/16 16:14

Thank s for your help so far
Posted By: Aku_Aku

Re: While in Trigger event - 11/25/16 18:05

I have a solution for such cases like this.
My idea was this:
When i need a cycle that runs independently from its originator
i make a new function that contains the loop. Like this:
Code:
action Whatever() {
  ... prepare the call ...
  myCustomFunction(with, any, parameter)
}

function myCustomFunction(with, any, parameter) {
  while(my_condition_is_true) {
    ... do anything important ...
  }
}


Notice that, in the real life the order of these two function is reversed, so the compiler can work with them.

I handled with this way for example panels, input texts and so on. Just like as you want in your opening post.
Hope this helps.
© 2024 lite-C Forums