Gamestudio Links
Zorro Links
Newest Posts
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 05:41
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (AbrahamR, AndrewAMD), 1,278 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Can I store pointers in local variables, or entity skills? #386873
11/10/11 08:26
11/10/11 08:26
Joined: Nov 2007
Posts: 50
C
Chaeon Offline OP
Junior Member
Chaeon  Offline OP
Junior Member
C

Joined: Nov 2007
Posts: 50
I want to attach a few passable visible entities to one invisible entity.

To do this the visible entities will have to regularly read the invisible entity's position, or the invisible entity will have to regularly write to the cosmetic entities' positions (the second method is better, i think)

before, i was storing handles in the invisible ent's skills and converting them back into pointers every frame, but then i looked closer at the manual and i suspect it's possible to just write pointers straight to skills (although they won't survive saving and loading which is fine)

is this wrong? and if it's right what type of variable do i need to store a pointer? The manual seemed to favour float yet when i tried to copy a pointer to a global variable as a test i got an error message for float, but not short or var.

i'm sorry for such a long question everyone, thank you for any help laugh

Re: Can I store pointers in local variables, or entity skills? [Re: Chaeon] #386877
11/10/11 09:54
11/10/11 09:54
Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
txesmi Offline
Serious User
txesmi  Offline
Serious User

Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
Hello,
This is the way I use entity skills as entity pointers

Code:
#include <acknex.h>

VECTOR vtemp;

function main ()
{
	wait(2);
	level_load ( "" );
	wait(3);
	camera.z = 100;
	camera.tilt = -90;
	
	you = ent_create ( CUBE_MDL, nullvector, NULL );
	
	set ( you, TRANSLUCENT );
	you.alpha = 30;
	
	you.skill1 = ent_create ( CUBE_MDL, vector(20,0,0), NULL );
	
	while (!key_esc)
	{
		you.pan += time_step * 10;
		you.tilt = fsin ( you.pan, 10 );
		
		vec_set ( vtemp, vector(10,0,0) );
		vec_rotate ( vtemp, you.pan );
		vec_add ( vtemp, you.x );
		
		vec_set ( ((ENTITY*)you.skill1)->x, vtemp );
		vec_set ( ((ENTITY*)you.skill1)->pan, you.pan );
		
		wait(1);
	}
	
	sys_exit ( NULL );
}



hope it helps,
txes

Re: Can I store pointers in local variables, or entity skills? [Re: txesmi] #386885
11/10/11 14:03
11/10/11 14:03
Joined: Dec 2008
Posts: 1,660
North America
Redeemer Offline
Serious User
Redeemer  Offline
Serious User

Joined: Dec 2008
Posts: 1,660
North America
What's wrong with handles? Granted, they're not as powerful as pointers but they should serve your purposes just fine.

Last edited by Redeemer; 11/10/11 14:04.

Eats commas for breakfast.

Play Barony: Cursed Edition!
Re: Can I store pointers in local variables, or entity skills? [Re: Chaeon] #386975
11/12/11 02:01
11/12/11 02:01
Joined: Nov 2007
Posts: 50
C
Chaeon Offline OP
Junior Member
Chaeon  Offline OP
Junior Member
C

Joined: Nov 2007
Posts: 50
Thank you for the advice

so it is possible to store the contents of a pointer in a skill.

and i can change the x,y,z etc of the entity referred to like this:

((ENTITY*)you.skill1)->x += number

(i don't understand this, what is a "->"? i'd be grateful if someone can point me to an explanation for it but it isn't crucial now)

thank you txesmi!


redeemer, i thought that storing the handle for an object and then converting it BACK into a pointer for use was a roundabout way to do things. But if i repeatedly did the arrow thing it might end up even slower running! i don't know.

I suppose my question is, then, what would be the most efficient way of storing a reference to an object in an entity skill, and then altering the position of said object every frame thereafter?

(the efficient way *might* be to store a handle, i don't know. But the manual says that the speed of ptr_for_handle is "medium" so i don't feel like calling it dozens of times every frame)


I HEART 3DGS
Re: Can I store pointers in local variables, or entity skills? [Re: Chaeon] #386976
11/12/11 02:07
11/12/11 02:07
Joined: Dec 2008
Posts: 1,660
North America
Redeemer Offline
Serious User
Redeemer  Offline
Serious User

Joined: Dec 2008
Posts: 1,660
North America
Handles are pretty stupid but they are the easiest way to handle this situation in Gamestudio. I don't think you can store a pointer to an engine object in a variable in Lite-C, although I may be wrong.

At any rate, another option for you to consider is to define an object pointer in your entity's action. Every entity that runs said action should thus have access to its own proper object pointer.


Eats commas for breakfast.

Play Barony: Cursed Edition!
Re: Can I store pointers in local variables, or entity skills? [Re: Redeemer] #386979
11/12/11 03:18
11/12/11 03:18
Joined: Nov 2007
Posts: 50
C
Chaeon Offline OP
Junior Member
Chaeon  Offline OP
Junior Member
C

Joined: Nov 2007
Posts: 50
what. doesn't that mean there's such a thing as a "local" pointer? but that would make it a hundred times easier!

I thought the only "local" pointers were my and you.

if i can just define a pointer inside a function and trust it to be preserved during wait(1), despite all the other entities using pointers of the same name, that would surely be the most efficient way?

wow i just tested it and it works. man why did they have a section on local variables in the manual yet nothing on local pointers? okay so i'll assume this is the most efficient way, but i'll be happy to hear any further wisdom.

Thank you very much for you time redeemer laugh


I HEART 3DGS
Re: Can I store pointers in local variables, or entity skills? [Re: Chaeon] #386987
11/12/11 10:05
11/12/11 10:05
Joined: Apr 2007
Posts: 3,751
Canada
WretchedSid Offline
Expert
WretchedSid  Offline
Expert

Joined: Apr 2007
Posts: 3,751
Canada
Uh, a pointer is nothing else than a variable, so the section about local variables already covers pointers...


Shitlord by trade and passion. Graphics programmer at Laminar Research.
I write blog posts at feresignum.com
Re: Can I store pointers in local variables, or entity skills? [Re: WretchedSid] #386997
11/12/11 13:54
11/12/11 13:54
Joined: Jul 2001
Posts: 6,904
H
HeelX Offline
Senior Expert
HeelX  Offline
Senior Expert
H

Joined: Jul 2001
Posts: 6,904
One additional note: it is OK to use local pointers and this works (like you already found out), but it is additional memory overhead, because the scheduler has to save and restore each frame for each function the local variables. So, if you just do

Code:
my->skill1 = ent_create(...)



And later in your code:

Code:
ENTITY* mySomething = (ENTITY*)my->skill1;



you are perfectly fine and don't waste memory and time.

[EDIT]
"." is used on structs and real objects, "->" is used on pointers. See here: http://publications.gbdirect.co.uk/c_book/

Last edited by HeelX; 11/12/11 13:55.
Re: Can I store pointers in local variables, or entity skills? [Re: HeelX] #387000
11/12/11 14:11
11/12/11 14:11
Joined: Dec 2008
Posts: 1,660
North America
Redeemer Offline
Serious User
Redeemer  Offline
Serious User

Joined: Dec 2008
Posts: 1,660
North America
Thanks for clearing that up HeelX. I remember being able to store pointers in variables without any trouble in C-Script but I wasn't sure if it was possible in Lite-C.


Eats commas for breakfast.

Play Barony: Cursed Edition!
Re: Can I store pointers in local variables, or entity skills? [Re: HeelX] #387032
11/13/11 00:56
11/13/11 00:56
Joined: Nov 2007
Posts: 50
C
Chaeon Offline OP
Junior Member
Chaeon  Offline OP
Junior Member
C

Joined: Nov 2007
Posts: 50
Thanks HeelX, i think i get it now, i'll use that way then..


I HEART 3DGS

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