Gamestudio Links
Zorro Links
Newest Posts
Data from CSV not parsed correctly
by EternallyCurious. 04/25/24 10:20
Trading Journey
by howardR. 04/24/24 20:04
M1 Oversampling
by Petra. 04/24/24 10:34
Zorro FIX plugin - Experimental
by flink. 04/21/24 07:12
Scripts not found
by juergen_wue. 04/20/24 18:51
zorro 64bit command line support
by 7th_zorro. 04/20/24 10:06
StartWeek not working as it should
by jcl. 04/20/24 08:38
folder management functions
by VoroneTZ. 04/17/24 06:52
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
3 registered members (EternallyCurious, Quad, vicknick), 700 guests, and 7 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Mega_Rod, EternallyCurious, howardR, 11honza11, ccorrea
19048 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
Entity pointer passed to function #344222
10/15/10 09:36
10/15/10 09:36
Joined: Jun 2006
Posts: 2,640
Earth
Germanunkol Offline OP
Expert
Germanunkol  Offline OP
Expert

Joined: Jun 2006
Posts: 2,640
Earth
We can't seem to figure this one out, though I guess the answer is prett simple.
The below code should - in my oppinion - stop counting up my_temp[0] as soon as "t" is pressed. When t is pressed, the entity counter in the F11 debug panel is set back to 0, so the entity IS removed. Still, the function which I passed the entity to keeps running.
I don't understand why I can manipulate inLight fine (inLight.x += time_step; for example) but inLight != NULL never returns 0, even when the entity does no longer exist.
Funny thing: my_temp[0] gets reset to 0 when I press t, but then keeps counting up. it's like the real entity is removed but replaced by some fake entity so the function can keep running?

Code:
var my_temp[9];
FONT* fallbackFont = "Arial#12b"; // truetype font 

PANEL* deb_pan = {
	pos_x = 20;
	pos_y = 300;
	layer = 1200;
	digits = 0,12,8.4,fallbackFont,1,my_temp[0];
}


void runWhileEntity(ENTITY* inLight)
{
	while(inLight != NULL)
	{
		inLight.x += time_step;
		my_temp[0] = inLight.x;
	}
	beep();
	beep();
	beep();
}

void main()
{
	set(deb_pan,SHOW);
	level_load(NULL);
	wait(3);
	
	ENTITY* theEnt;
	theEnt = ent_create(NULL,nullvector,NULL);

	runWhileEntity(theEnt);
	while(key_t == OFF) wait(1);
	ent_remove(theEnt);
}




~"I never let school interfere with my education"~
-Mark Twain
Re: Entity pointer passed to function [Re: Germanunkol] #344224
10/15/10 09:42
10/15/10 09:42
Joined: Apr 2007
Posts: 3,751
Canada
WretchedSid Offline
Expert
WretchedSid  Offline
Expert

Joined: Apr 2007
Posts: 3,751
Canada
Although you remove the ENTITY, the pointer still points to the memory area where the entity was. It doesn't gets set to NULL because you never set it to NULL.


Shitlord by trade and passion. Graphics programmer at Laminar Research.
I write blog posts at feresignum.com
Re: Entity pointer passed to function [Re: WretchedSid] #344231
10/15/10 11:00
10/15/10 11:00
Joined: Jun 2006
Posts: 2,640
Earth
Germanunkol Offline OP
Expert
Germanunkol  Offline OP
Expert

Joined: Jun 2006
Posts: 2,640
Earth
Well, ent_remove(theEnt); theEnt = NULL; doesn't work either, because it's not the same pointer.
So how do I set ENTITY* inLight to null? from outside the function? I can't, right? cause the scope of that variable's limited to the function...?



Last edited by Germanunkol; 10/15/10 11:00.

~"I never let school interfere with my education"~
-Mark Twain
Re: Entity pointer passed to function [Re: Germanunkol] #344232
10/15/10 11:24
10/15/10 11:24
Joined: Apr 2007
Posts: 3,751
Canada
WretchedSid Offline
Expert
WretchedSid  Offline
Expert

Joined: Apr 2007
Posts: 3,751
Canada
You can pass a pointer to a pointer like this:

Code:
void runWhileEntity(ENTITY** inLight)
{
	while(*inLight != NULL)
	{
		*inLight.x += time_step;
		my_temp[0] = *inLight.x;
	}
	beep();
	beep();
	beep();
}

void main()
{
	set(deb_pan,SHOW);
	level_load(NULL);
	wait(3);
	
	ENTITY* theEnt;
	theEnt = ent_create(NULL,nullvector,NULL);

	runWhileEntity(&theEnt);
	while(key_t == OFF) wait(1);
	ent_remove(theEnt);
	theEnt = NULL;
}




Shitlord by trade and passion. Graphics programmer at Laminar Research.
I write blog posts at feresignum.com
Re: Entity pointer passed to function [Re: WretchedSid] #344233
10/15/10 11:33
10/15/10 11:33
Joined: Oct 2007
Posts: 5,210
İstanbul, Turkey
Quad Online
Senior Expert
Quad  Online
Senior Expert

Joined: Oct 2007
Posts: 5,210
İstanbul, Turkey
use fuction as the action of the entity and use a while-me loop instead?


3333333333
Re: Entity pointer passed to function [Re: Quad] #344276
10/15/10 21:16
10/15/10 21:16
Joined: Apr 2009
Posts: 33
Germany
B
Bunsen Offline
Newbie
Bunsen  Offline
Newbie
B

Joined: Apr 2009
Posts: 33
Germany
If you are using tasks within Lite-C (by calling the "wait" function) there are 2 solutions to exchange data:
Either you use global variables or you must implement a messaging system e.g. a queque.
The pointer of pointer method is not working here (although ok in other multitasking systems) because
in Lite-C on reentry the stack is not originally reconstructed.

Re: Entity pointer passed to function [Re: Bunsen] #344298
10/16/10 00:11
10/16/10 00:11
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline
Expert
EvilSOB  Offline
Expert

Joined: Feb 2008
Posts: 3,232
Australia
Code:
#define i_am_alive skill55   //any unused skill number will do

void runWhileEntity(ENTITY** inLight)
{
	while(inLight.i_am_alive == true)
	{
		*inLight.x += time_step;
		my_temp[0] = *inLight.x;
		wait(1);
	}
	beep();
	beep();
	beep();
}

void main()
{
	set(deb_pan,SHOW);
	level_load(NULL);
	wait(3);
	
	ENTITY* theEnt;
	theEnt = ent_create(NULL,nullvector,NULL);
	theEnt.i_am_alive = true;

	runWhileEntity(&theEnt);
	while(key_t == OFF) wait(1);
	theEnt.i_am_alive = false;
	wait(1);   //critical!
	ent_remove(theEnt);
}




"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: Entity pointer passed to function [Re: Bunsen] #344308
10/16/10 06:54
10/16/10 06:54
Joined: Apr 2007
Posts: 3,751
Canada
WretchedSid Offline
Expert
WretchedSid  Offline
Expert

Joined: Apr 2007
Posts: 3,751
Canada
Originally Posted By: Bunsen
The pointer of pointer method is not working here (although ok in other multitasking systems) because
in Lite-C on reentry the stack is not originally reconstructed.

Wow, thanks for the info!


Shitlord by trade and passion. Graphics programmer at Laminar Research.
I write blog posts at feresignum.com
Re: Entity pointer passed to function [Re: Bunsen] #344309
10/16/10 07:29
10/16/10 07:29
Joined: Jan 2003
Posts: 4,615
Cambridge
Joey Offline
Expert
Joey  Offline
Expert

Joined: Jan 2003
Posts: 4,615
Cambridge
Originally Posted By: Bunsen
The pointer of pointer method is not working here (although ok in other multitasking systems) because in Lite-C on reentry the stack is not originally reconstructed.

honestly? why is that? and what has it to do with the stack? that would be extremely counter-intuitive if you could pass pointers to the heap and not to the stack. i thought that would be the whole point in the coroutine stuff.
so basically what you're saying is that *inLight is not guaranteed to be theEnt anymore?

Re: Entity pointer passed to function [Re: Joey] #344326
10/16/10 13:38
10/16/10 13:38
Joined: Dec 2008
Posts: 271
Saturnus Offline
Member
Saturnus  Offline
Member

Joined: Dec 2008
Posts: 271
There were some threads about this. Here is one of them:
http://www.opserver.de/ubb7/ubbthreads.php?ubb=showflat&Number=248692

Page 1 of 2 1 2

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