Gamestudio Links
Zorro Links
Newest Posts
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
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
3 registered members (AbrahamR, AndrewAMD, ozgur), 763 guests, and 7 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
string for entity pointer ? #282663
08/03/09 01:06
08/03/09 01:06
Joined: May 2009
Posts: 1,816
at my pc (duh)
darkinferno Offline OP
Serious User
darkinferno  Offline OP
Serious User

Joined: May 2009
Posts: 1,816
at my pc (duh)
I'm looking at a new way of re scripting some elements of my game and i came up with the thought of:

Code:
ENTITY*object1;
ENTITY*object2;

STRING*obj_name="object1";

function blah()
{
 set(obj_name,INVISIBLE);  
}



but it doesn't work, the reason i wanted to do this was so i could use one short function and affect whichever entity i choose just by editing the STRING...

any ideas on this?

Re: string for entity pointer ? [Re: darkinferno] #282664
08/03/09 01:32
08/03/09 01:32
Joined: Jul 2008
Posts: 1,178
England
M
MrGuest Offline
Serious User
MrGuest  Offline
Serious User
M

Joined: Jul 2008
Posts: 1,178
England
heya, have a look at engine_getvar()

Re: string for entity pointer ? [Re: darkinferno] #282670
08/03/09 04:05
08/03/09 04:05
Joined: Sep 2005
Posts: 75
CA, Orange County
Gerrit Offline
Junior Member
Gerrit  Offline
Junior Member

Joined: Sep 2005
Posts: 75
CA, Orange County
Hi
I don't know if that is possible but why don't you give the pointer as an argument when you call your function?

Gerrit

Re: string for entity pointer ? [Re: Gerrit] #282681
08/03/09 07:25
08/03/09 07:25
Joined: May 2009
Posts: 1,816
at my pc (duh)
darkinferno Offline OP
Serious User
darkinferno  Offline OP
Serious User

Joined: May 2009
Posts: 1,816
at my pc (duh)
Originally Posted By: Gerrit
Hi
I don't know if that is possible but why don't you give the pointer as an argument when you call your function?

Gerrit
noobish question but am not that great at all the programming elements yet, could you give me an example of this? i mean, i do have workarounds but i'm just looking an easier and faster way, it would also help in other areas...

Re: string for entity pointer ? [Re: darkinferno] #282702
08/03/09 10:25
08/03/09 10:25
Joined: Jul 2002
Posts: 4,436
Germany, Luebeck
Xarthor Offline
Expert
Xarthor  Offline
Expert

Joined: Jul 2002
Posts: 4,436
Germany, Luebeck
Did you try:
- ent_for_name (STRING* name);

Problem here: You can only use names which you set by using WED. At least thats how I understood the documentation about the command.

Re: string for entity pointer ? [Re: Xarthor] #282711
08/03/09 11:13
08/03/09 11:13
Joined: Jun 2006
Posts: 2,640
Earth
Germanunkol Offline
Expert
Germanunkol  Offline
Expert

Joined: Jun 2006
Posts: 2,640
Earth
Maybe I misunderstand what you're trying to do, but this should do the trick:

Code:
ENTITY* toSetInvisibleEnt;

void blah()
{
  ENTITY* currentInvisible;
  while(1)
  {
    if(currentInvisible != toSetInvisibleEnt){
       reset(currentInvisible,INVISIBLE);
       currentInvisible = toSetInvisibleEnt;
       set(currentInvisible,INVISIBLE);
    }
    wait(1);
  }
}

function blahaaa()
{
  while(my)
  {

    //do your stuff
    if(something or other is true)
    toSetInvisibleEnt = my;
    wait(1);
  }
}




~"I never let school interfere with my education"~
-Mark Twain
Re: string for entity pointer ? [Re: Germanunkol] #282720
08/03/09 12:01
08/03/09 12:01
Joined: May 2009
Posts: 1,816
at my pc (duh)
darkinferno Offline OP
Serious User
darkinferno  Offline OP
Serious User

Joined: May 2009
Posts: 1,816
at my pc (duh)
ok, let me try and simplify this.. basically all i want to do is use a string to refer to an entity pointer, so instead of

ENTITY*box;

set(box,INVISIBLE);

i could have:


ENTITY*box;

STRING* somestring= "box";

set(somestring,INVISIBLE);

why would i want to do this? well, this way i could juet edit the string to refer to another entity and that new enitity would get invisible.

Re: string for entity pointer ? [Re: darkinferno] #282722
08/03/09 12:20
08/03/09 12:20
Joined: Jul 2002
Posts: 4,436
Germany, Luebeck
Xarthor Offline
Expert
Xarthor  Offline
Expert

Joined: Jul 2002
Posts: 4,436
Germany, Luebeck
The problem is: how do you want to identify the very object you want to edit?
A pointer is a memory address to a specific entity and thus you can edit that very entity.
A string with "box" inside is hard to translate to a specific entity.
Because how do you want to identify it?
By the filename? What about multiple instances of a file then?

You can use either the filename or you use a name which you attached to an entity using WED and use the command ent_for_name

You could also store the name in a skill or in string1/2.
Then you have to search the entity in the list of entities and then edit it.

Re: string for entity pointer ? [Re: Xarthor] #282733
08/03/09 12:49
08/03/09 12:49
Joined: Dec 2008
Posts: 271
Saturnus Offline
Member
Saturnus  Offline
Member

Joined: Dec 2008
Posts: 271
To associate a pointer with a string you could also use a hash map (see GSHashmap by pegamode) or a similar data structure. This should be considered if you need many string lookups per frame, because a linear search is much slower.


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