[Not a bug] Weird string array behaviour

Forum rules
Please don't bump threads here if you have a problem - it will often be forgotten about if you do. Instead, make a new thread here.

Post a reply

Smilies
:D :) :( :o :shock: :? 8-) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :wink: :geek: :ugeek: :!: :?: :idea: :arrow: :| :mrgreen: :3: :wub: >:( :blergh:
View more smilies

BBCode is OFF
Smilies are ON

Topic review
   

Expand view Topic review: [Not a bug] Weird string array behaviour

by boris » Mon Nov 03, 2003 2:59 pm

Yay, works nice!

by randi » Mon Nov 03, 2003 2:51 pm

Just make the first string you use in your script "", and then your arrays will be initialized to "". It could be as simple as this, if you like:

Code: Select all

#include "zcommon.acs" 
str AnEmptyString = "";

str bla[5]; 

script 1 open 
{ 
   bla[0] = "heh"; 

   print(s:bla[0], s:"\n", s:bla[1], s:"\n", s:bla[2], s:"\n", s:bla[3], s:"\n", s:bla[4]); 
}
You could even stick

Code: Select all

str AnEmptyString = "";
in zcommon.acs if you want.

by boris » Mon Nov 03, 2003 2:35 pm

Ah, seems pretty logical :) Still a bit uncomfortable though. Especially when you got several string arrays.

by Chris » Mon Nov 03, 2003 2:25 pm

Strings are referenced by index in ACS, not pointers like in C. When you declare a string, it's set to 0, meaning index 0(1st of 256 strings), until assigned something else. So when you set bla[0] to "heh"(the first string, index 0), all strings that reference index 0, will display "heh", until you change them.

Weird string array behaviour

by boris » Mon Nov 03, 2003 2:15 pm

Hi!

I found some od string array behaviour. Try this little script:

Code: Select all

#include "zcommon.acs"

str bla[5];

script 1 open
{
	bla[0] = "heh";

	print(s:bla[0], s:"\n", s:bla[1], s:"\n", s:bla[2], s:"\n", s:bla[3], s:"\n", s:bla[4]);
}
It will display "heh" 5 times, i.e. all fields of the array get filled with "heh", and not only the very first one. Shouldn't they be set to "" or NULL or something by default?

Top