Gamestudio Links
Zorro Links
Newest Posts
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
M1 Oversampling
by 11honza11. 04/30/24 08:16
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
4 registered members (NeoDumont, dr_panther, AndrewAMD, TedMar), 1,429 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
flag event #427600
08/10/13 13:38
08/10/13 13:38
Joined: Mar 2012
Posts: 44
A
Abarudra Offline OP
Newbie
Abarudra  Offline OP
Newbie
A

Joined: Mar 2012
Posts: 44
Hey there,

just a quick question. I have many entities in my level which dont have a while loop in their action. The only purpose of the action is to set the skills to certain values.
I now want to execute one function (which contains the entity-pointer as parameter) when one of the entitys flags is set to 1.
Do i realy have to add a while loop just to check once for if(my.flagX), or is it possible to have something like an event-function that is only triggered when a flag gets set to 1?

Regards

Re: flag event [Re: Abarudra] #427631
08/11/13 00:23
08/11/13 00:23
Joined: Jun 2013
Posts: 108
Alberta, Canada
C
CanadianDavid Offline
Member
CanadianDavid  Offline
Member
C

Joined: Jun 2013
Posts: 108
Alberta, Canada
No, there is no event for flag detection. However, if you are colliding with these entities you can check if is(you,FLAG1) returns True or False. If there are many entities you want to check if the FLAG is set you can scan through all entities on the map via ent_next and check if the returned entity pointer has its FLAG set.

You will have to describe your problem more fully (possibly with an example) for the best solution to be recommended. It is possible that you can use one of the many EVENTS already defined; please see the Gamestudio Manual for all the possible EVENTS.

Re: flag event [Re: Abarudra] #427636
08/11/13 02:51
08/11/13 02:51
Joined: Jan 2002
Posts: 4,225
Germany / Essen
Uhrwerk Offline
Expert
Uhrwerk  Offline
Expert

Joined: Jan 2002
Posts: 4,225
Germany / Essen
Originally Posted By: Abarudra
Do i realy have to add a while loop just to check once for if(my.flagX)

The while loop is one possibility.
Originally Posted By: Abarudra
or is it possible to have something like an event-function that is only triggered when a flag gets set to 1?

Not natively. But you can easily call that function every time after manipulating the skill:
Code:
my_special_ent->skill1 += 1;
skill_was_changed(my_special_ent);


If you're doing this frequently you can also write a setter function:
Code:
void set_skill1(ENTITY* ent,fixed value)
{
  if (!ent)
    return;

  ent->skill1 = value;

  skill_was_changed(ent);
}



Always learn from history, to be sure you make the same mistakes again...
Re: flag event added - code example [Re: Uhrwerk] #427638
08/11/13 08:52
08/11/13 08:52
Joined: Mar 2012
Posts: 44
A
Abarudra Offline OP
Newbie
Abarudra  Offline OP
Newbie
A

Joined: Mar 2012
Posts: 44
Thank you for your ideas, i will try it.

You are right i should have added more details. I have this situation.

The entities i mentioned are remote triggered explosives. The action sets several skills set the damage, delay, aoe etc. I store the pointer of this entity in a skill of the detonator-entity.
I want to detonate it by setting one of its flags to 1 and then execute the explosion function.

The problem is this function contains an ent_create function, and it is necessary that the you pointer for the created entity is set to the explosive and not to the detonator.
I will try to get my code in a readable state and post it here. Ok i dont have access to my computer right now, so i will just post a general example
-- EDIT --
Code:
1. The Detonator

void trigger_explo(ENTITY* explosive) // Will set the Flag of the saved entity to 1
{
   [...]
   set(explosive,FLAG1);
   [...]
}

action detonator()    // Has stored all explosives-pointer in its entity-skills
{
   [...]
   my.skill1 = spawn_explosive(); // create explosive and save its pointer
   while(1)
   {
      [...]
      if(i_want_to detonate)      // check if eg. button for detonation is pressed
      {
         trigger_explo((ENTIY*) my.skill1);
         [...]
      }
      wait(1);
   }
}

2. The Explosive

void detonate_ent()   // aoe damage and shrapnelspawning
{
   [...]
   ent_create("shrapnel.mdl",my.x,shrapnel_func);
   //you.parent = me;
}

void explosive_ent()
{
   [...]
   set_stats_from_other_source(source); // With this function i save the stats of the explosive and the generated shrapnels in skills of this entity 
   
   while(1)
   {
      if(is(my,FLAG1)){detonate_ent();} // i just would like to avoid many entities with short loops that check only for one changing flag
      wait(1);
   }
}

3. The Shrapnel

void set_stats_from(ENTITY* from) // all properties of the shrapnel are save in skills in the explosive_entiy
{
   my.skill10 = from.skill10;
}

void shrapnel_func()
{
   set_stats_from(you); // get stats from your creator
   [...]
   while(1)
   {
      do_stuff();
      wait(1);
   }
}

I know i can avoid the whileloop if i run detonate_ent() inside the detonator action. But then you would point to the detonator and not the explosive.
It would work if i save the stats in detonator.skills instead of explosive.skills, but i want to avoid that if possible, cause i dont have enough free skills if i want to support the number of explosives i need.


I hope my idea is now better to understand and i thank you for ideas / answers.

Regards

Last edited by Abarudra; 08/11/13 13:29. Reason: Codeexample added
Re: flag event added - code example [Re: Abarudra] #427647
08/11/13 14:10
08/11/13 14:10
Joined: Mar 2012
Posts: 44
A
Abarudra Offline OP
Newbie
Abarudra  Offline OP
Newbie
A

Joined: Mar 2012
Posts: 44
added codeexample to previous post.

Re: flag event added - code example [Re: Abarudra] #427648
08/11/13 14:38
08/11/13 14:38
Joined: Apr 2007
Posts: 3,751
Canada
WretchedSid Offline
Expert
WretchedSid  Offline
Expert

Joined: Apr 2007
Posts: 3,751
Canada
Set the you pointer yourself to the explosive, then call detonate_ent(). Something like this should work:

Code:
void trigger_explo(ENTITY* explosive) // Will set the Flag of the saved entity to 1
{
   wait(1); // This is important as it returns to the caller, and gives us the chance to alter the you pointer opaque to the caller but visible to our callees

   you = explosive;
   detonate_ent();
}



Shitlord by trade and passion. Graphics programmer at Laminar Research.
I write blog posts at feresignum.com
Re: flag event added - code example [Re: WretchedSid] #427649
08/11/13 14:48
08/11/13 14:48
Joined: Mar 2012
Posts: 44
A
Abarudra Offline OP
Newbie
Abarudra  Offline OP
Newbie
A

Joined: Mar 2012
Posts: 44
Thank you JustSid,

i will give it a try. I had sth. similar before but i forgot the "wait(1);"

My approach was this

Code:
ENTITY* created = ent_create(...);
created.skill1 = explosive;

But it crashed because i checked the skill before it had the right value.


Re: flag event added - code example [Re: Abarudra] #427652
08/11/13 15:44
08/11/13 15:44
Joined: Mar 2012
Posts: 44
A
Abarudra Offline OP
Newbie
Abarudra  Offline OP
Newbie
A

Joined: Mar 2012
Posts: 44
Ok i have tried it.
But it seems i have interpreted your code wrong or i'm just stupid.
If i set the you pointer before the ent_create, shouldn't it be overwritten?

I wrote this code to check it
Code:
#include <acknex.h>
#include <atypes.h>
#include <default.c>

void bomb()
{
	my.skill3 = 100;
}

void shard()
{
        wait(1); // <-- added
	//my.skill1 = you.skill3;
        my.skill1 = my.parent.skill3; // <-- added
	while(1)
	{
		my.pan -= my.skill1*time_step;
		wait(1);
	}	
}

void detonate_ent(ENTITY* e)
{
	//ent_create(CUBE_MDL,vector(my.x,my.y,my.z+200),shard);
        ENTIY* created = ent_create(CUBE_MDL,vector(my.x,my.y,my.z+200),shard); //<-- added
        created.parent = e; // <-- added

}

void trigger_ent(ENTITY* e)
{	
	//wait(1);
	//you=e;
        // detoante_ent(you);
	detonate_ent(e); //<-- added
}

void detonator()
{
	ENTITY* test= ent_create(CUBE_MDL,vector(0,100,0),bomb);
	my.skill3 = 1;
	while(1)
	{
		if(key_d){trigger_ent(test);return;}
		wait(1);
	}
}

function main()
{
	video_switch(8,0,2);
	level_load(NULL);
	vec_set(screen_color,vector(255,0,0)); // blau 
	wait(3);
	fps_max = 60;
	ent_create(CUBE_MDL,nullvector,detonator);
	camera.x -= 1000;
}


The shard in this example is rotating slowly (as expected) cause its skill1 is set to 1 and not to 100 as i need it to be.
Ok i think i was too fast. I made a view changes and now i think its working for now.
The removed parts are commented and the new lines are marked with "//<-- added"

Last edited by Abarudra; 08/11/13 15:46.

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