Newbie Question: Arrays

Get Help on scripting in POL with configurations, config setups, script trouble shooting, etc.
Post Reply
DevGIB
Grandmaster Poster
Posts: 248
Joined: Mon Feb 06, 2006 6:12 am

Newbie Question: Arrays

Post by DevGIB »

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
Pierce
Forum Regular
Posts: 420
Joined: Thu Feb 02, 2006 8:33 am

Post by Pierce »

If you declare it directly in a file it looks that way:

cprop onID a3:i1i2i3
DevGIB
Grandmaster Poster
Posts: 248
Joined: Mon Feb 06, 2006 6:12 am

Post by DevGIB »

what about strings in arrays?
Pierce
Forum Regular
Posts: 420
Joined: Thu Feb 02, 2006 8:33 am

Post by Pierce »

That's nearly the same except the string length:

cprop onID a3:i1S4:testi3
DevGIB
Grandmaster Poster
Posts: 248
Joined: Mon Feb 06, 2006 6:12 am

Post by DevGIB »

ok awesome thanks heaps man
DevGIB
Grandmaster Poster
Posts: 248
Joined: Mon Feb 06, 2006 6:12 am

Post by DevGIB »

hrmm i tested it and it doesnt seem to respond correctly... it consideres the number and the : to be part of the string... is that the correct syntax?

eg
s4:none
returns
4:none ingame
User avatar
Austin
Former Developer
Posts: 621
Joined: Wed Jan 25, 2006 2:30 am

Post by Austin »

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:

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
Yukiko
Distro Developer
Posts: 2826
Joined: Thu Feb 02, 2006 1:41 pm

Post by Yukiko »

Relating to this topic, does case matter in the array declaration in the file?

Is this:
cprop onID a3:i1i2i3

the same as this:
cprop onID A3:I1I2I3

?
DevGIB
Grandmaster Poster
Posts: 248
Joined: Mon Feb 06, 2006 6:12 am

Post by DevGIB »

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...
Jasaka
New User
Posts: 9
Joined: Sun Feb 05, 2006 3:49 am

Post by Jasaka »

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.
Pierce
Forum Regular
Posts: 420
Joined: Thu Feb 02, 2006 8:33 am

Post by Pierce »

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 :wink:

If the cfg file called aaa.cfg looks that way:

Code: Select all

Test 1
{
    onID a3:i1S4:testi3
}
You will get your array with the following code:

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

Post by Firedancer »

Jasaka 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.
true... you can type these strings manually into the config file too, but your syntax is wrong. It's: a3:i1i2i3


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.
User avatar
Austin
Former Developer
Posts: 621
Joined: Wed Jan 25, 2006 2:30 am

Post by Austin »

If you take a data type, and pass it to the Pack() function, it will return how it looks when you type it into your config files manually.

Works on anything. Just try the code sample I gave. Faith!
DevGIB
Grandmaster Poster
Posts: 248
Joined: Mon Feb 06, 2006 6:12 am

Post by DevGIB »

ok well il will try the pack code you offered on my script it was just that .prop edit wasnt returning the cprop right it was turning everything in the array after s (string) into the string... ill give it a shot and let you know, thanks for your help
Post Reply