1 registered members (TipmyPip),
18,631
guests, and 7
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
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
OP
Member
|
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]
#304329
01/06/10 18:52
01/06/10 18:52
|
Joined: Sep 2009
Posts: 1,032 Budapest
Aku_Aku
Serious User
|
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:
PANEL* cardpanels[500];
STRING* panelnames[500];
Store the pointers and the names when they occurs. For example:
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:
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
Expert
|
Expert
Joined: Jan 2004
Posts: 3,023
The Netherlands
|
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  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.
|
|
|
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
Serious User
|
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? 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
Expert
|
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
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
|
|
|
|