Strings in arrays

You must understand the Game Editor concepts, before post here.

Strings in arrays

Postby Jukeri » Sat Jul 27, 2013 2:07 pm

I am trying to make a reporting system in our game, that would take random phrases from different arrays setup to store situational responses and reporting (such as loss of something, frontline advance, etc.) and possibly modify parts of them by changing single words from the base phrases so that it doesn't end up being monotone. Some stuff such as names etc would also be stored in these arrays.

I'm having a problem with arrays and strings; I've tried a coupple of methods I googled and dug up from the forum but none seem to work or print out anything. I guess I'm missing out something important in handling string arrays in C and GEscript.

I've tried making the arrays
Code: Select all
const char *cmdnames;[20]
cmdnames[0] = "Lieutenant Powell";
cmdnames[1] = "Sergeant Mason";

And
Code: Select all
char cmdnames[20][15];
strcpy(cmdnames[0], "Lieutenant Powell";
strcpy(cmdnames[1], "Sergeant Mason";


What is a good way to store arrays/print them out later in GEscript? Also, how can I do a console-like printing output (so that it adds a newline then prints a new row of text after the previous row.)
Currently working on Radio Ops (to be changed)
Progress: 20%
Jukeri
 
Posts: 6
Joined: Thu Jul 18, 2013 9:36 am
Score: 0 Give a positive score

Re: Strings in arrays

Postby skydereign » Sun Jul 28, 2013 8:33 am

Jukeri wrote:I've tried making the arrays
Code: Select all
const char *cmdnames;[20]
cmdnames[0] = "Lieutenant Powell";
cmdnames[1] = "Sergeant Mason";

And
Code: Select all
char cmdnames[20][15];
strcpy(cmdnames[0], "Lieutenant Powell";
strcpy(cmdnames[1], "Sergeant Mason";

You are setting string arrays properly assuming you meant this by your second code.
Code: Select all
char cmdnames[20][15];
strcpy(cmdnames[0], "Lieutenant Powell)";
strcpy(cmdnames[1], "Sergeant Mason");

Now that variable cmdnames will only exist within the script that code is in. If you want to have it accessible elsewhere you need to declare it as a global variable.
Jukeri wrote:What is a good way to store arrays/print them out later in GEscript? Also, how can I do a console-like printing output (so that it adds a newline then prints a new row of text after the previous row.)

You can display text in gE using text actors. To create a text actor, give a normal actor a font file, and some default text (click the [Text] button in the actor control panel dialog). Then you can use strcpy, or other string functions on that actor's text variable. Due to the nature of the text variable, namely its limit of 255 characters, if you want to create a console like print mechanism I would suggest spawning clones that represent each new line of text.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Strings in arrays

Postby Jukeri » Sun Jul 28, 2013 12:22 pm

Alright, sounds good, but how do I then use that string stored in an array? It just empties the target string/text object if I try sprintf or strcpy or other command
Currently working on Radio Ops (to be changed)
Progress: 20%
Jukeri
 
Posts: 6
Joined: Thu Jul 18, 2013 9:36 am
Score: 0 Give a positive score


Return to Advanced Topics

Who is online

Users browsing this forum: No registered users and 1 guest

cron