Gamestudio Links
Zorro Links
Newest Posts
zorro license, IB connection
by miwok. 12/06/23 16:32
Newbie Questions
by fairtrader. 12/06/23 11:29
Zorro Trader GPT
by TipmyPip. 12/04/23 11:34
Square root rule
by Smallz. 12/02/23 09:15
RTest not found error
by TipmyPip. 12/01/23 21:43
neural function for Python to [Train]
by TipmyPip. 12/01/23 14:47
Xor Memory Problem.
by TipmyPip. 11/28/23 14:23
Training with command line parameters
by TipmyPip. 11/26/23 08:42
AUM Magazine
Latest Screens
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Tactics of World War I
Who's Online Now
6 registered members (miwok, AndrewAMD, TipmyPip, 3run, Quad, 1 invisible), 645 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
fairtrader, hus, Vurtis, Harry5, KelvinC
19019 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
how to create a pointer to a pointer? #341936
09/22/10 02:22
09/22/10 02:22
Joined: Sep 2010
Posts: 82
P
peteredlin Offline OP
Junior Member
peteredlin  Offline OP
Junior Member
P

Joined: Sep 2010
Posts: 82
Hello, i am using the following function:

name = ent_create(...,...,...);

Now i wanna use name as string variable containing the name of the entity (pointer)

I cant figure out how to do it



Last edited by peteredlin; 09/22/10 20:50.
Re: how to create a pointer to a pointer? [Re: peteredlin] #341937
09/22/10 02:48
09/22/10 02:48
Joined: May 2010
Posts: 117
Germany , Dortmund
B
Bone Offline
Member
Bone  Offline
Member
B

Joined: May 2010
Posts: 117
Germany , Dortmund
A Pointer to an ENTITY != String with Name

To get the name of the ENTITY you can use str_for_entname(STRING, ENTITY);

STRING* model_name;
ENTITY* my_ent = ent_create(...);
str_for_entname(model_name, my_ent);

//now model_name containing the name like "cube.mdl"

Re: how to create a pointer to a pointer? [Re: Bone] #341954
09/22/10 08:25
09/22/10 08:25
Joined: Sep 2003
Posts: 928
Spirit Offline

Moderator
Spirit  Offline

Moderator

Joined: Sep 2003
Posts: 928
That will crash. You must not write something into an unassigned pointer.

STRING* model_name = "";

Re: how to create a pointer to a pointer? [Re: Spirit] #341978
09/22/10 12:52
09/22/10 12:52
Joined: Sep 2007
Posts: 62
Germany
B
bodden Offline
Junior Member
bodden  Offline
Junior Member
B

Joined: Sep 2007
Posts: 62
Germany
@Spirit: You are right. First you have to assign the pointer to something.

But do you know the reason for that? When you assign the pointer to an empty string ("\n", so a 1 Byte cell) and after that you call the str_for_entname, what does happen? Will the entname be copied into some "new" storage cells and the pointer will be reassigned?
Or will there be a reallocation of storage cells, the pointer is pointing to, and after that the entname is been copied into that cells?
Either way: It seems to make no sense to assign the pointer before using it.

Last edited by bodden; 09/22/10 13:01.
Re: how to create a pointer to a pointer? [Re: bodden] #341988
09/22/10 13:33
09/22/10 13:33
Joined: Sep 2003
Posts: 928
Spirit Offline

Moderator
Spirit  Offline

Moderator

Joined: Sep 2003
Posts: 928
I believe the str_ commands adjust the string to the new length, make it longer or shorter. So it does not matter when you assign it to an empty string, it just must be assigned to some string.

Re: how to create a pointer to a pointer? [Re: Spirit] #342029
09/22/10 19:45
09/22/10 19:45
Joined: Sep 2009
Posts: 987
Budapest
Aku_Aku Offline
User
Aku_Aku  Offline
User

Joined: Sep 2009
Posts: 987
Budapest
Just a short addendum.
You can create string also like this:
STRING* mystring;
...
mystring=str_create("");
...
and later
...
str_for_entname(mystring, my_ent);

Re: how to create a pointer to a pointer? [Re: Aku_Aku] #342034
09/22/10 20:12
09/22/10 20:12
Joined: Sep 2010
Posts: 82
P
peteredlin Offline OP
Junior Member
peteredlin  Offline OP
Junior Member
P

Joined: Sep 2010
Posts: 82
Hello , i think i havent explained my problem well anough.
Let me try again:

code:

ENTITY* pointer_name;


Now i want to use a string variable for pointer_name, so i can use this single line of code to declare a few ENTITY pointers.

Hope i explained it better.


or a simpler question:How to create a pointer to a pointer.

Last edited by peteredlin; 09/22/10 20:48.
Re: how to create a pointer to a pointer? [Re: peteredlin] #342043
09/22/10 20:59
09/22/10 20:59
Joined: May 2007
Posts: 2,043
Germany
Lukas Offline

Programmer
Lukas  Offline

Programmer

Joined: May 2007
Posts: 2,043
Germany
I don't know what exactly you mean by all this talking about strings, but a pointer to a pointer would look like this:
ENTITY** pointer_to_a_pointer;

Re: how to create a pointer to a pointer? [Re: Lukas] #342061
09/23/10 01:43
09/23/10 01:43
Joined: Sep 2010
Posts: 82
P
peteredlin Offline OP
Junior Member
peteredlin  Offline OP
Junior Member
P

Joined: Sep 2010
Posts: 82
My problem is envolved in the following code:

///////////////////////////////////////////////////////////////
#include <acknex.h>
#include <default.c>

///////////////////////////////////////////////////////////////
ENTITY*ball;




function create_ent(entpointer)
{

entpointer = ent_create("p360_frame.mdl",vector(0,0,0),NULL);

}

function main()
{
level_load("small.hmp");
create_ent(ball);
}

Now when i run the code it looks like it runs well, but when i type TAB and then ball.x=50 , nothing happens. Why not?

Re: how to create a pointer to a pointer? [Re: peteredlin] #342062
09/23/10 02:33
09/23/10 02:33
Joined: Nov 2007
Posts: 1,143
United Kingdom
DJBMASTER Offline
Serious User
DJBMASTER  Offline
Serious User

Joined: Nov 2007
Posts: 1,143
United Kingdom
Code:
#include <acknex.h>
#include <default.c>

ENTITY* ball;

function create_ent(ENTITY** entpointer)
{
*entpointer = ent_create("p360_frame.mdl",vector(0,0,0),NULL);
}

function main()
{
level_load("small.hmp");
create_ent(ball);
}



Page 1 of 2 1 2

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