2 registered members (AndrewAMD, juanex),
1,247
guests, and 6
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
string arrays
#425391
07/03/13 23:22
07/03/13 23:22
|
Joined: Nov 2008
Posts: 354 saeculum II
MPQ
OP
Senior Member
|
OP
Senior Member
Joined: Nov 2008
Posts: 354
saeculum II
|
hi,
is it possible to initialize string arrays such as:
STRING *myString[2] = { "a", "b"};
this example throws an error message, but is there any way I can get this workin?
new project in early stage...
Intel Xeon X3450 2,66GHz | Mushkin 8 Gib | Zotac GTS250 + 7300LE | A8.3 com
|
|
|
Re: string arrays
[Re: MPQ]
#425392
07/03/13 23:23
07/03/13 23:23
|
Malice
Unregistered
|
Malice
Unregistered
|
Use the string array build into the TEXT* object.. Look up TEXT in engine objects in the manual. Take a look at how it was used here http://www.opserver.de/ubb7/ubbthreads.php?ubb=showflat&Number=424023#Post424041 It also sound right to make a array of pointers and fill it later.
STRING* array_strings[1000];
function this_func()
{ var x;
for(x=0;x<1000;x++)
{
array_strings[x] = str_create(" Some Text");
}
}
Last edited by Malice; 07/04/13 04:14.
|
|
|
Re: string arrays
[Re: ]
#425451
07/05/13 11:36
07/05/13 11:36
|
Joined: Nov 2008
Posts: 354 saeculum II
MPQ
OP
Senior Member
|
OP
Senior Member
Joined: Nov 2008
Posts: 354
saeculum II
|
thank you, but the I have the problem that
my_text->string = array_strings[0]
doesnt work!
Last edited by MPQ; 07/05/13 11:36.
new project in early stage...
Intel Xeon X3450 2,66GHz | Mushkin 8 Gib | Zotac GTS250 + 7300LE | A8.3 com
|
|
|
Re: string arrays
[Re: sivan]
#425487
07/06/13 11:37
07/06/13 11:37
|
Joined: Nov 2008
Posts: 354 saeculum II
MPQ
OP
Senior Member
|
OP
Senior Member
Joined: Nov 2008
Posts: 354
saeculum II
|
wow thanks thats workin fine.
hopefully my last question: I wanna use a text array as well, such as
TEXT* my_text[2]
str_cpy((my_text[0]->pstring)[7], my_str[0]);
but I get an error message!
new project in early stage...
Intel Xeon X3450 2,66GHz | Mushkin 8 Gib | Zotac GTS250 + 7300LE | A8.3 com
|
|
|
Re: string arrays
[Re: MPQ]
#425488
07/06/13 11:40
07/06/13 11:40
|
Joined: Jun 2009
Posts: 2,210 Bavaria, Germany
Kartoffel
Expert
|
Expert
Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
|
when using TEXT like this you have to allocate memory manually (afaik) or use something like text_create (if such thing exists) because you don't really create a text object but an array of pointers.
POTATO-MAN saves the day! - Random
|
|
|
Re: string arrays
[Re: Kartoffel]
#425489
07/06/13 12:06
07/06/13 12:06
|
Joined: Nov 2008
Posts: 354 saeculum II
MPQ
OP
Senior Member
|
OP
Senior Member
Joined: Nov 2008
Posts: 354
saeculum II
|
hmm ye I see I am tryin to figure sth out
new project in early stage...
Intel Xeon X3450 2,66GHz | Mushkin 8 Gib | Zotac GTS250 + 7300LE | A8.3 com
|
|
|
Re: string arrays
[Re: MPQ]
#425493
07/06/13 14:02
07/06/13 14:02
|
Joined: Jan 2002
Posts: 4,225 Germany / Essen
Uhrwerk
Expert
|
Expert
Joined: Jan 2002
Posts: 4,225
Germany / Essen
|
TEXT* my_text[2]
str_cpy((my_text[0]->pstring)[7], my_str[0]); You have no idea what you're doing, have you? This is wrong syntax as well as nonsense. Read about operator precendece. Don't try to create an array of texts. The text object already has an array of strings. When using text objects you have to create them with http://www.conitec.net/beta/atxt_create.htm.
Always learn from history, to be sure you make the same mistakes again...
|
|
|
Re: string arrays
[Re: MPQ]
#425495
07/06/13 14:55
07/06/13 14:55
|
Joined: Sep 2009
Posts: 993 Budapest
Aku_Aku
User
|
User
Joined: Sep 2009
Posts: 993
Budapest
|
Before you copy a string into a string, you have to initialize the target (if this usage of the string will be the first). Like this:
TEXT* txt_TxtContent[16];
...
for(inx=0; inx <16; inx++) {
txt_TxtContent[inx] = txt_create(1,0);
}
Last edited by Aku_Aku; 07/06/13 14:56.
|
|
|
Re: string arrays
[Re: Aku_Aku]
#426142
07/17/13 07:10
07/17/13 07:10
|
Joined: Oct 2002
Posts: 2,256 Oz
Locoweed
Expert
|
Expert
Joined: Oct 2002
Posts: 2,256
Oz
|
TEXT* txtGoals = { strings = 16; }
TEXT* txtGoalsList = { string ("Whatever","Blah Blah","Oh Yeah baby!"); }
str_cpy((txtGoals.pstring)[0],"Whatever"); str_cpy((txtGoals.pstring)[1],"Blah Blah");
or
(txtGoals.pstring)[0] = (txtGoalsList.pstring)[0]; // "Whatever"
(txtGoals.pstring)[1] = (txtGoalsList.pstring)[1]; // "Blah Blah"
You know, whatever, Later, Loco
Professional A8.30 Spoils of War - East Coast Games
|
|
|
|