Gamestudio Links
Zorro Links
Newest Posts
Executing Trades on Next Bar Open
by Zheka. 06/20/24 14:26
Lapsa's very own thread
by rki. 06/19/24 11:27
A simple game ...
by VoroneTZ. 06/18/24 10:50
Face player all the time ...
by bbn1982. 06/18/24 10:25
Zorro Beta 2.61: PyTorch
by jcl. 06/10/24 14:42
New FXCM FIX Plugin
by flink. 06/04/24 07:30
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (Martin_HH, TipmyPip), 1,279 guests, and 10 spiders.
Key: Admin, Global Mod, Mod
Newest Members
squik, AemStones, LucasJoshua, Baklazhan, Hanky27
19060 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Pointer to pointer? #280369
07/22/09 12:10
07/22/09 12:10
Joined: May 2004
Posts: 1,510
Denmark
Claus_N Offline OP
Serious User
Claus_N  Offline OP
Serious User

Joined: May 2004
Posts: 1,510
Denmark
Hi,

It seems that it is not possible to use a pointer to a pointer in Lite-C - can anyone confirm this?

The manual didn't seem to say anything about it frown

I tried testing it with this code, which resulted in a crash ("invalid arguments"):
Code:
void test(RPGItem** _temp)
{
	str_cat(_temp.name,"\ntest");
}



Re: Pointer to pointer? [Re: Claus_N] #280373
07/22/09 12:34
07/22/09 12:34
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline
Expert
EvilSOB  Offline
Expert

Joined: Feb 2008
Posts: 3,232
Australia
You DEFINATELY CAN use pointers to pointers (to pointers even).
I use them with multi-dimensional arrays often.

Without seeing your RPGItem struct, I cant be sure, but try (in this order)
str_cat(_temp->name,"\ntest");
or
str_cat((_temp)->name,"\ntest");
or
str_cat((*_temp)->name,"\ntest");

The "->" is required, assuming that "name" is a string pointer.


"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: Pointer to pointer? [Re: EvilSOB] #280377
07/22/09 12:40
07/22/09 12:40
Joined: May 2004
Posts: 1,510
Denmark
Claus_N Offline OP
Serious User
Claus_N  Offline OP
Serious User

Joined: May 2004
Posts: 1,510
Denmark
Thanks for the reply smile

It was the "RPGItem** _temp" function parameter I was refering to though, it seems to produce a crash, so I thought it couldn't be done? confused

It's been quite a while since I've been using C++, but afaik that was how to do it in C++.

Re: Pointer to pointer? [Re: Claus_N] #280384
07/22/09 13:22
07/22/09 13:22
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline
Expert
EvilSOB  Offline
Expert

Joined: Feb 2008
Posts: 3,232
Australia
Thats right, Ive passed pointer-to-a-pointer's that way without issue before.

Can you post the code that calls the 'test' function.
And the code that builds the data too.
So I can see the logic behind why you need to call it as a pointer-to-a-pointer.
In case theres a bug in that somewhere...


"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: Pointer to pointer? [Re: EvilSOB] #280387
07/22/09 13:31
07/22/09 13:31
Joined: May 2004
Posts: 1,510
Denmark
Claus_N Offline OP
Serious User
Claus_N  Offline OP
Serious User

Joined: May 2004
Posts: 1,510
Denmark
I was doing it just for testing purposes, though here's the code using the function:
Code:
// In function main
RPGItem* testItem;
testItem.type = 2;
testItem.name = testStr;
test(&testItem);


and the struct so far:
Code:
typedef struct RPGItem
{
	var type;
	int cellsX;
	int cellsY;
	BMAP* bmap;
	STRING* name;
} RPGItem;



Edit: this is the first time I'm trying to use Lite-C so it wouldn't surprise me if I missed something grin
Edit 2: I tried using a pointer-to-a-pointer of an integer instead, and it worked, so I'm probably just missing something smile
Edit 3 grin: Tried this and it does work:
Code:
void test(RPGItem** _temp)
{
	(**_temp).type = 2;
}



Last edited by Claus_N; 07/22/09 13:40.
Re: Pointer to pointer? [Re: Claus_N] #280390
07/22/09 13:43
07/22/09 13:43
Joined: May 2004
Posts: 1,510
Denmark
Claus_N Offline OP
Serious User
Claus_N  Offline OP
Serious User

Joined: May 2004
Posts: 1,510
Denmark
Seems it wasn't the "RPGItem**" which caused the problem anyways. I got the string working as well:

Code:
str_cpy((**_temp).name,"test");



My bad, sorry, it's been a while since I've used C-style pointers grin

Thanks for your time smile

Re: Pointer to pointer? [Re: Claus_N] #280394
07/22/09 14:04
07/22/09 14:04
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline
Expert
EvilSOB  Offline
Expert

Joined: Feb 2008
Posts: 3,232
Australia
With what you have, you dont need a pointer-to-a-pointer. (all below code is tested)
Code:
void _test(RPGItem *_temp)
{
	str_cat(_temp->name,"\ntest");
}

// In function main
RPGItem testItem;
testItem.type = 2;
testItem.name = str_create(_chr(testStr));
_test(&testItem);



Unless your items are going into an array like this....
Code:
void _test(RPGItem *_temp)
{
	str_cat(_temp->name,"\ntest");
}

// In function main
RPGItem *testItem = malloc(sizeof(RPGItem)*20);		
var i; for(i=0; i<20; i++)   { memset(testItem[i],0,sizeof(RPGItem)); }
testItem[0].type = 2;
testItem[0].name = str_create(_chr(testStr));
_test(&testItem[0]);




"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: Pointer to pointer? [Re: EvilSOB] #280398
07/22/09 14:19
07/22/09 14:19
Joined: May 2004
Posts: 1,510
Denmark
Claus_N Offline OP
Serious User
Claus_N  Offline OP
Serious User

Joined: May 2004
Posts: 1,510
Denmark
I was just testing whether it was possible in Lite-C, as I would be using it later on while writing my inventory system wink

(I'm re-writing my old c-script inventory in Lite-C smile )

Re: Pointer to pointer? [Re: Claus_N] #280400
07/22/09 14:21
07/22/09 14:21
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline
Expert
EvilSOB  Offline
Expert

Joined: Feb 2008
Posts: 3,232
Australia
Kewl, would be nice to see.
Public use? Or trade secret code? (just curious)


"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: Pointer to pointer? [Re: EvilSOB] #280406
07/22/09 14:33
07/22/09 14:33
Joined: May 2004
Posts: 1,510
Denmark
Claus_N Offline OP
Serious User
Claus_N  Offline OP
Serious User

Joined: May 2004
Posts: 1,510
Denmark
For a small RPG project ( http://www.zofteyez.dk/azarinath/ ). I'll probably make an inventory like this for "public use" later, but it depends on the amount of homework :P

Last edited by Claus_N; 07/22/09 14:33. Reason: typo

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