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
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
3 registered members (7th_zorro, TipmyPip, RealSerious3D), 892 guests, and 4 spiders.
Key: Admin, Global Mod, Mod
Newest Members
firatv, wandaluciaia, Mega_Rod, EternallyCurious, howardR
19050 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
While in Trigger event #463236
11/23/16 07:49
11/23/16 07:49
Joined: Oct 2008
Posts: 681
Germany
Ayumi Offline OP
User
Ayumi  Offline OP
User

Joined: Oct 2008
Posts: 681
Germany
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);	
}


Re: While in Trigger event [Re: Ayumi] #463239
11/23/16 10:58
11/23/16 10:58
Joined: May 2009
Posts: 5,370
Caucasus
3run Offline
Senior Expert
3run  Offline
Senior Expert

Joined: May 2009
Posts: 5,370
Caucasus
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!


Looking for free stuff?? Take a look here: http://badcom.at.ua
Support me on: https://boosty.to/3rung
Re: While in Trigger event [Re: 3run] #463240
11/23/16 11:21
11/23/16 11:21
Joined: Oct 2008
Posts: 681
Germany
Ayumi Offline OP
User
Ayumi  Offline OP
User

Joined: Oct 2008
Posts: 681
Germany
Thanks for your response, but that not solve the problem.

Re: While in Trigger event [Re: Ayumi] #463241
11/23/16 11:24
11/23/16 11:24
Joined: May 2009
Posts: 5,370
Caucasus
3run Offline
Senior Expert
3run  Offline
Senior Expert

Joined: May 2009
Posts: 5,370
Caucasus
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!


Looking for free stuff?? Take a look here: http://badcom.at.ua
Support me on: https://boosty.to/3rung
Re: While in Trigger event [Re: 3run] #463243
11/23/16 12:10
11/23/16 12:10
Joined: Oct 2008
Posts: 681
Germany
Ayumi Offline OP
User
Ayumi  Offline OP
User

Joined: Oct 2008
Posts: 681
Germany
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.

Re: While in Trigger event [Re: Ayumi] #463244
11/23/16 12:32
11/23/16 12:32
Joined: May 2009
Posts: 5,370
Caucasus
3run Offline
Senior Expert
3run  Offline
Senior Expert

Joined: May 2009
Posts: 5,370
Caucasus
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!


Looking for free stuff?? Take a look here: http://badcom.at.ua
Support me on: https://boosty.to/3rung
Re: While in Trigger event [Re: 3run] #463245
11/23/16 12:58
11/23/16 12:58
Joined: Oct 2008
Posts: 681
Germany
Ayumi Offline OP
User
Ayumi  Offline OP
User

Joined: Oct 2008
Posts: 681
Germany
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..)

Last edited by Ayumi; 11/23/16 13:01.
Re: While in Trigger event [Re: Ayumi] #463249
11/23/16 15:48
11/23/16 15:48
Joined: May 2009
Posts: 5,370
Caucasus
3run Offline
Senior Expert
3run  Offline
Senior Expert

Joined: May 2009
Posts: 5,370
Caucasus
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.


Looking for free stuff?? Take a look here: http://badcom.at.ua
Support me on: https://boosty.to/3rung
Re: While in Trigger event [Re: 3run] #463251
11/23/16 16:14
11/23/16 16:14
Joined: Oct 2008
Posts: 681
Germany
Ayumi Offline OP
User
Ayumi  Offline OP
User

Joined: Oct 2008
Posts: 681
Germany
Thank s for your help so far

Re: While in Trigger event [Re: Ayumi] #463272
11/25/16 18:05
11/25/16 18:05
Joined: Sep 2009
Posts: 993
Budapest
Aku_Aku Offline
User
Aku_Aku  Offline
User

Joined: Sep 2009
Posts: 993
Budapest
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.


Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

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