Newbie Question: Arrays
Newbie Question: Arrays
declaring arrays on items in cfg files... just wondering how its done... cos ive been having some trouble and cant figure it out
cprop onID a{1,2,3}
thats what i figured it would be but it doesnt seem to work
thanks in advanced
cprop onID a{1,2,3}
thats what i figured it would be but it doesnt seem to work
thanks in advanced
To make it easier, try building your variable by hand, then output it with Pack() in basic.em and youll get the string for it. 
Example:
Example:
Code: Select all
use os;
use basic;
program SomeProgram()
var my_var := array{1, "help", struct{"A":=1}, dictionary{"B"=>1024}};
Print("-> "+Pack(my_var));
endprogram
thanks austin but i have no problems using arrays in scripts... its the cfg file that i have he problems with... ill explain what im trying to do to make it alittle easier...
i want to make it so that certain things can be writen in the cfg file to trigger effects on id e.g. for gm weaps rather than having the normal id sysmessage it will say something different kinda thing... i also wanna store the name of the weap in the array in the cfg but for some reason s26:abcdefghijklmnopqrstuvwxtyz
would come through as 25:abcdefghijklmnopqrstuvwxyz and if i put any other parts of the array behind it it will add them to that string aswell...
i want to make it so that certain things can be writen in the cfg file to trigger effects on id e.g. for gm weaps rather than having the normal id sysmessage it will say something different kinda thing... i also wanna store the name of the weap in the array in the cfg but for some reason s26:abcdefghijklmnopqrstuvwxtyz
would come through as 25:abcdefghijklmnopqrstuvwxyz and if i put any other parts of the array behind it it will add them to that string aswell...
I am not sure if i understood you right. But i try to post a solution for a config file. I personally would prefer datafiles for such actions
If the cfg file called aaa.cfg looks that way:
You will get your array with the following code:
If the cfg file called aaa.cfg looks that way:
Code: Select all
Test 1
{
onID a3:i1S4:testi3
}
Code: Select all
use uo;
use cfgfile;
use basic;
program test(who)
var t := ReadConfigFile("aaa");
var e := FindConfigElem(t, 1);
var s := GetConfigString(e, "onID");
var tt := unpack(s);
endprogram
-
Firedancer
- Grandmaster Poster
- Posts: 104
- Joined: Fri Feb 03, 2006 6:32 am
true... you can type these strings manually into the config file too, but your syntax is wrong. It's: a3:i1i2i3Jasaka wrote:But Austin didn't said 'you must do it by script', this script what he posted is easier way to do from this { 1, 2, 3 } to this a3:i1:i2:i3.
I have never tried if it works with capital letters though... if you want to know, why, just try it, sure simple enough to do. Anyway though, the syntax works as follows:
Arrays: a<number of array entries>:<entry1><entry2>...<entryx>
Integers: i<value>
Strings: s<length of string>:<stringtext>
so an array { 1, hello, {2,3}} stored on an item's cprop would require this line in the itemdesc.cfg
cprop mycpropname a3:i1s5:helloa2:i2i3
ps: I'm not 100% sure on strings and I got no idea how structs are stored... but above are plenty samples how you can figure it out.