String & var (HELP)

Non-platform specific questions.

String & var (HELP)

Postby micolord » Wed Nov 09, 2011 9:00 am

How can I make a GLOBAL STRING variable in a script when activated? :) and is there any way to do this:

stringvar = {"","","","",""}

I don't know why this does not work.
I suck so bad.
micolord
 
Posts: 21
Joined: Sun Nov 06, 2011 7:29 am
Location: Philippines
Score: 0 Give a positive score

Re: String & var (HELP)

Postby skydereign » Wed Nov 09, 2011 9:59 am

You need to declare the type of the variable. Strings in C happen to be arrays of chars. So, to declare a string, you can use this.
Code: Select all
char string[10];
char string_2[10] = "hello";
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: String & var (HELP)

Postby micolord » Wed Nov 09, 2011 10:14 am

Aw....... I don't get it :S

cant it be?

char string[] = {"","","","",""};

and how can i insert a value inside the char table?
I suck so bad.
micolord
 
Posts: 21
Joined: Sun Nov 06, 2011 7:29 am
Location: Philippines
Score: 0 Give a positive score

Re: String & var (HELP)

Postby micolord » Wed Nov 09, 2011 10:17 am

Also how can I make it GLOBAL VARIABLE?
I suck so bad.
micolord
 
Posts: 21
Joined: Sun Nov 06, 2011 7:29 am
Location: Philippines
Score: 0 Give a positive score

Re: String & var (HELP)

Postby skydereign » Wed Nov 09, 2011 10:21 am

You can kind of do it that way... but you can't use double quotes, you'd have to use single quotes. Also, you would need some character within the single quotes. And if you wanted to insert individual characters, you can use this.
Code: Select all
char string[] = "hello";
string[0]='H';
// string now holds Hello

strcpy(string, "Test");
// string now holds Test

// and many other string functions


And to make it a global variable, put it into global code.
Global Code
Code: Select all
char string[10];

With that script added, you'll have a 10 character long global string.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: String & var (HELP)

Postby micolord » Wed Nov 09, 2011 10:23 am

Thanks I will try it.
I suck so bad.
micolord
 
Posts: 21
Joined: Sun Nov 06, 2011 7:29 am
Location: Philippines
Score: 0 Give a positive score

Re: String & var (HELP)

Postby micolord » Wed Nov 09, 2011 10:27 am

Crap....... I suck.... put it in Global Code right? how do I save it? Because it got only CLOSE option then when I press it, it says: Your code has been altered. Do you want to close anyway?
I suck so bad.
micolord
 
Posts: 21
Joined: Sun Nov 06, 2011 7:29 am
Location: Philippines
Score: 0 Give a positive score

Re: String & var (HELP)

Postby skydereign » Wed Nov 09, 2011 10:54 am

1. Click [Global Code].
2. Type your script.
3. Input a name for the script.
4. Click [Add].
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: String & var (HELP)

Postby micolord » Wed Nov 09, 2011 11:52 am

Okay I did the steps.... the Global Code I did:

charName[] = "";

script name: charName_var
then press ADD button

so after that I used my "charName[]" in other event script:

charName[0] = "H";

ERROR:

Unknown Type in boncost & Invalid assignment
I suck so bad.
micolord
 
Posts: 21
Joined: Sun Nov 06, 2011 7:29 am
Location: Philippines
Score: 0 Give a positive score

Re: String & var (HELP)

Postby skydereign » Wed Nov 09, 2011 11:03 pm

First of all, charName is the variable name. You need to put a space between char and Name. Second, that declares a string of size 0. When dealing with strings in c, you need to set a max size. You seem adamant to not setting it, but it is something you need to do. So pick a size that you won't exceed. Lastly, in case you didn't know, if you want to use the string, you don't add the [] because that dereferences the array, to give you a single char.
Code: Select all
char Name[10];

// if you want to edit a single character
Name[0] = 'A';
// you need the variable name, followed by [#] where # is replaced with a number that is less than the inputted size

// if you want to use the entire string, than you just use Name
strcpy(text, Name);
// displays the string using text
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: String & var (HELP)

Postby micolord » Thu Nov 10, 2011 4:00 am

Well I'm trying to make a table array, how can I make a table array?

EDIT: Nevermind, lol got it :3
I suck so bad.
micolord
 
Posts: 21
Joined: Sun Nov 06, 2011 7:29 am
Location: Philippines
Score: 0 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest