Gamestudio Links
Zorro Links
Newest Posts
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
M1 Oversampling
by 11honza11. 04/30/24 08:16
Trading Journey
by howardR. 04/28/24 09:55
Zorro Trader GPT
by TipmyPip. 04/27/24 13:50
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
3 registered members (Quad, Ayumi, AndrewAMD), 1,092 guests, and 1 spider.
Key: Admin, Global Mod, Mod
Newest Members
firatv, wandaluciaia, Mega_Rod, EternallyCurious, howardR
19050 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
Array of strings #246762
01/17/09 00:43
01/17/09 00:43
Joined: Nov 2008
Posts: 8
R
roBurky Offline OP
Newbie
roBurky  Offline OP
Newbie
R

Joined: Nov 2008
Posts: 8
I am trying to create an array of strings, but I'm being given a syntax error. Is what I'm trying to do possible in lite-c? My programming experience is in Java.
Code:
	STRING imageGreen[2] = { "screen_nointruders.bmp", "screen_knowyourenemy.bmp" };



Re: Array of strings [Re: roBurky] #246764
01/17/09 00:50
01/17/09 00:50
Joined: Jan 2008
Posts: 1,580
Blade280891 Offline
Serious User
Blade280891  Offline
Serious User

Joined: Jan 2008
Posts: 1,580
Erm im not sure how to do it direct but try
STRING * imageGreen[2] = { "screen_nointruders.bmp", "screen_knowyourenemy.bmp" };
or
STRING * imageGreen[2];
imageGreen[1] = "screen_nointruders.bmp";//Should this not be 0, or does lite-c start at 1
imageGreen = "screen_knowyourenemy.bmp";


My Avatar Randomness V2

"Someone get me to the doctor, and someone call the nurse
And someone buy me roses, and someone burned the church"
Re: Array of strings [Re: Blade280891] #246768
01/17/09 01:14
01/17/09 01:14
Joined: Nov 2008
Posts: 8
R
roBurky Offline OP
Newbie
roBurky  Offline OP
Newbie
R

Joined: Nov 2008
Posts: 8
Thanks for responding, Blade.

If I try your second suggestion, then the first line goes through ok, but the second and third lines get another error message.
Quote:
Can not convert 'ARRAY' to 'struct STRING'


Re: Array of strings [Re: roBurky] #246773
01/17/09 03:32
01/17/09 03:32
Joined: Apr 2006
Posts: 624
DEEP 13
badapple Offline
User
badapple  Offline
User

Joined: Apr 2006
Posts: 624
DEEP 13
dont know if this helps you,its taken right from the manual and looks like a way of creating an array of strings to me



TEXT willkommen
{
...
strings = 5; // 5 differenet string pointes
string = willkommen, dies_ist, ein, text,string1;
}

...

my_text.string[3] = new_string;

Re: Array of strings [Re: badapple] #246779
01/17/09 05:51
01/17/09 05:51
Joined: Jul 2005
Posts: 1,002
Trier, Deutschland
Nowherebrain Offline
Serious User
Nowherebrain  Offline
Serious User

Joined: Jul 2005
Posts: 1,002
Trier, Deutschland
I thought you would use....

willkomen.pstring[0] = "_words and numbers and such 1!!";
willkomen.pstring[1];
willkomen.pstring[2];
willkomen.pstring[3];
willkomen.pstring[4];

that would be 5 strings.
and my_text.pstring would be wrong...you would use the name of the TEXT* object/element

Last edited by Nowherebrain; 01/17/09 05:55.

Everybody Poops.
here are some tutorials I made.
http://www.acknexturk.com/blender/
Re: Array of strings [Re: Nowherebrain] #246833
01/17/09 14:43
01/17/09 14:43
Joined: Nov 2008
Posts: 8
R
roBurky Offline OP
Newbie
roBurky  Offline OP
Newbie
R

Joined: Nov 2008
Posts: 8
Thank you, I've made progress due to your replies, badapple and Nowherebrain. Looking at the command help for pstring gave an example of an array of strings, which I've used to create the array successfully (I think).

Code:
TEXT tScreenGreen =
{
string ("screen_knowyourenemy.bmp", "screen_nointruders.bmp");
}



And then through a lot more trial and error, figured out that I needed to use this to access it:
Code:
(tScreenGreen.pstring)[0]


So thanks everyone! I'm back on track.

Re: Array of strings [Re: roBurky] #246868
01/17/09 17:37
01/17/09 17:37
Joined: Jul 2008
Posts: 894
T
TechMuc Offline
User
TechMuc  Offline
User
T

Joined: Jul 2008
Posts: 894
the correct syntax for a string array

STRING** tst;
tst = malloc(sizeof(STRING*),number of elements);
for(int i=0;i<number of elements;i++)
tst[i]=str_create("#number of characters");

now you can access the string array like this:

str_cpy(tst[0],"hallo");

Re: Array of strings [Re: TechMuc] #248023
01/23/09 22:46
01/23/09 22:46
Joined: Jul 2004
Posts: 1,710
MMike Offline
Serious User
MMike  Offline
Serious User

Joined: Jul 2004
Posts: 1,710
Nice trick..

Re: Array of strings [Re: MMike] #248034
01/23/09 23:52
01/23/09 23:52
Joined: Apr 2006
Posts: 737
Ottawa, Canada
O
Ottawa Offline
User
Ottawa  Offline
User
O

Joined: Apr 2006
Posts: 737
Ottawa, Canada
Hi!

Thanks for the information TechMuc. That might be the solution to my post.

I think that there is a syntax error in the first line that was presented
by roBurky
STRING imageGreen[2] = { "screen_nointruders.bmp", "screen_knowyourenemy.bmp" };
should have been
STRING imageGreen[2] = ( "screen_nointruders.bmp", "screen_knowyourenemy.bmp" );

Ottawa smile

Re: Array of strings [Re: Ottawa] #253722
02/26/09 10:58
02/26/09 10:58
Joined: Feb 2009
Posts: 33
Germany, Hamburg
V
Vorick Offline
Newbie
Vorick  Offline
Newbie
V

Joined: Feb 2009
Posts: 33
Germany, Hamburg
Sorry to dig up a post that's been inactive for a month. I hope this doesn't count as resurrecting dead threads.

I'm currently working with string arrays myself in order to generate an onscreen-log for the server-side of my game. Although techmuc's post provided me with the solution to my problem, there seems to be a typo in it and I just want to spare anyone else finding this topic the headache.

malloc uses only one parameter and therefore you have to multiply the number of elements with sizeof(STRING*). The code below should be the correct one and is working in my scenario.

Code:
STRING** tst;
tst = malloc(sizeof(STRING*) * number of elements);
for(int i=0;i<number of elements;i++)
tst[i]=str_create("#number of characters");

//now you can access the string array like this:

str_cpy(tst[0],"hallo");


Last edited by Vorick; 02/26/09 10:59.

A8.10 Commercial
Page 1 of 2 1 2

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