Gamestudio Links
Zorro Links
Newest Posts
Zorro 2.70
by jcl. 09/29/25 09:24
optimize global parameters SOLVED
by dBc. 09/27/25 17:07
ZorroGPT
by TipmyPip. 09/27/25 10:05
assetHistory one candle shift
by jcl. 09/21/25 11:36
Plugins update
by Grant. 09/17/25 16:28
AUM Magazine
Latest Screens
Rocker`s Revenge
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Who's Online Now
1 registered members (TipmyPip), 18,449 guests, and 6 spiders.
Key: Admin, Global Mod, Mod
Newest Members
krishna, DrissB, James168, Ed_Love, xtns
19168 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
function parameter panel does not work with strings #304316
01/06/10 17:08
01/06/10 17:08
Joined: Apr 2008
Posts: 144
Germany | Niedersachsen (Lower...
Roxas Offline OP
Member
Roxas  Offline OP
Member

Joined: Apr 2008
Posts: 144
Germany | Niedersachsen (Lower...
Hey guys, I've got a Problem.
Its difficult to explain but i hope you can help me.

I have 2 functions
the first has two parameters


function set_cardpos(PANEL* panel, position)
{
[...]
}


the second function is just a normal function. I work with panels. I've got a panel for every card that should appear depending on the card amount the player got.

now i want to make a loop that saves a lot of work.
it looks like this:

while(counter < cards+1)
{
str_cpy(cardname, "atk_card");
str_for_num(cardnum, counter);
str_cat(cardname, cardnum);

set_cardpos(cardname, 250);

counter += 1;
wait(1);
}

this while loop is element of the second function.
i wanted to create a string that holds the name of the panel. when the parameters reach the other function it should add the name of the desired panel for "panel" but it doesn't do this. nothing happens. when i type in the desired panel myself (f.e. "atk_card1") for "cardname" in the "set_cardpos(cardname, 250);"-line it does work.

do you know whats the matter about this?

i hope so

best regards
Roxas

Last edited by Roxas; 01/06/10 17:09.
Re: function parameter panel does not work with strings [Re: Roxas] #304319
01/06/10 17:15
01/06/10 17:15
Joined: Jan 2004
Posts: 3,023
The Netherlands
Helghast Offline
Expert
Helghast  Offline
Expert

Joined: Jan 2004
Posts: 3,023
The Netherlands
it's expecting a panel, you're passing over a string...
you somehow need to convert the string into an actual panel.

good luck.

regards,


Formerly known as dennis_fantasy
Portfolio - http://www.designorhea.com/
Project - http://randomchance.cherrygames.org/
Re: function parameter panel does not work with strings [Re: Helghast] #304320
01/06/10 17:33
01/06/10 17:33
Joined: Apr 2008
Posts: 144
Germany | Niedersachsen (Lower...
Roxas Offline OP
Member
Roxas  Offline OP
Member

Joined: Apr 2008
Posts: 144
Germany | Niedersachsen (Lower...
yeah thats the point
I hoped that 3dgs would convert it somehow through the parameter transfer or would "read" the string and put the string's content in place of the panel.

well someone here who has experience with converting strings to panels?

i hope so. and thanks for the answer helghast


best regards

roxas

Re: function parameter panel does not work with strings [Re: Roxas] #304329
01/06/10 18:52
01/06/10 18:52
Joined: Sep 2009
Posts: 1,032
Budapest
Aku_Aku Offline
Serious User
Aku_Aku  Offline
Serious User

Joined: Sep 2009
Posts: 1,032
Budapest
Try to build two arrays, one for panel pointers, another for the names.
Store each panel pointers and regarding the names paralell.
Like this:
Code:
PANEL* cardpanels[500];
STRING* panelnames[500];



Store the pointers and the names when they occurs.
For example:
Code:
panelnames[5]="5thcard";
cardpanels[5]=pan_create(NULL,2);
cardpanels[5].bmap = bmap_create("nicecard.tga");
cardpanels[5].pos_x=400;
cardpanels[5].pos_y=200;
...
set other panel attributes



You can organize this activity into a loop if you can load the datas from file or create somehow the datas and the names.
In this case you have to save everything in a file, open that and read all lines. Just for fun:
Code:
for(index=0; index<500; index++) {
	file_str_read(fhnd_n,mystring);
	posx=file_var_read();
	posy=file_var_read();
	panelnames[index]=mystring;
	cardpanels[index]=pan_create(NULL,2);
	cardpanels[index].bmap = bmap_create(mystring);
	cardpanels[index].pos_x=posx;
	cardpanels[index].pos_y=posx;
}



Re: function parameter panel does not work with strings [Re: Roxas] #304387
01/07/10 11:11
01/07/10 11:11
Joined: Jan 2004
Posts: 3,023
The Netherlands
Helghast Offline
Expert
Helghast  Offline
Expert

Joined: Jan 2004
Posts: 3,023
The Netherlands
Originally Posted By: Roxas
yeah thats the point
I hoped that 3dgs would convert it somehow through the parameter transfer or would "read" the string and put the string's content in place of the panel.

well someone here who has experience with converting strings to panels?

i hope so. and thanks for the answer helghast


best regards

roxas


Wow, in my post i wante to write down "sorry I cant really help, im a bit braindead...", after reading it again with some sleep, my post was the most helpless ever, im sorry i stated something you obviously had found out already (and had written in the description, hahahaa).

Anyway, basically what aku_aku did will work.
However personally im not a fan of preset length's of arrays (I wish array's would be more dynamic.. dammit), so instead you could use a linked list... but that's just being nitpicky me there wink

Good luck, and again sorry for the lame post...

regards,

EDIT: just to contribute to this topic, this should also work for what i said about dynamic array's:
array of STRIGNS [EvilSOB]

Last edited by Helghast; 01/07/10 11:15.

Formerly known as dennis_fantasy
Portfolio - http://www.designorhea.com/
Project - http://randomchance.cherrygames.org/
Re: function parameter panel does not work with strings [Re: Helghast] #304400
01/07/10 13:34
01/07/10 13:34
Joined: Sep 2009
Posts: 1,032
Budapest
Aku_Aku Offline
Serious User
Aku_Aku  Offline
Serious User

Joined: Sep 2009
Posts: 1,032
Budapest
I am courios what is your opinion why is this comment at the bottom of the Wiki page?
Quote:
Seriously, don't use this code, this is an example of what not to do. --alexh 07:20, 24 October 2009 (CEST)


Re: function parameter panel does not work with strings [Re: Aku_Aku] #304455
01/08/10 03:39
01/08/10 03:39
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline
Expert
EvilSOB  Offline
Expert

Joined: Feb 2008
Posts: 3,232
Australia
I would guess its because that code is so old and the engine has improved a lot since then, so that is not very efficient code anymore.

NOWADAYS I can think of two very different ways of achieving that same result.

But the one based on my wiki example should should be updated to
Code:
STRING** string_array = sys_malloc(sizeof(STRING*) * number_of_elements);
int i=0;   for(i=0; i<number_of_elements; i++) 
{      string_array[i] = str_create("");     }

//now you can access the string array like this:
str_cpy(string_array[0],"hallo");




"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | 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