PenUltima Online

It is currently Fri Sep 05, 2008 9:50 am

All times are UTC - 8 hours




Post new topic Reply to topic  [ 14 posts ] 
Author Message
 Post subject: Newbie Question: Arrays
PostPosted: Mon Feb 06, 2006 6:14 am 
Offline

Joined: Mon Feb 06, 2006 6:12 am
Posts: 93
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


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 06, 2006 6:30 am 
Offline

Joined: Thu Feb 02, 2006 8:33 am
Posts: 276
If you declare it directly in a file it looks that way:

cprop onID a3:i1i2i3


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 07, 2006 6:16 am 
Offline

Joined: Mon Feb 06, 2006 6:12 am
Posts: 93
what about strings in arrays?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 07, 2006 7:11 am 
Offline

Joined: Thu Feb 02, 2006 8:33 am
Posts: 276
That's nearly the same except the string length:

cprop onID a3:i1S4:testi3


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 07, 2006 8:32 am 
Offline

Joined: Mon Feb 06, 2006 6:12 am
Posts: 93
ok awesome thanks heaps man


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 07, 2006 8:41 am 
Offline

Joined: Mon Feb 06, 2006 6:12 am
Posts: 93
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


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 07, 2006 9:25 am 
Offline
POL Developer
User avatar

Joined: Wed Jan 25, 2006 2:30 am
Posts: 405
Location: San Diego, California
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:
use os;
use basic;

program SomeProgram()
     var my_var := array{1, "help", struct{"A":=1}, dictionary{"B"=>1024}};
     Print("-> "+Pack(my_var));
endprogram

_________________
-Austin


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 07, 2006 1:28 pm 
Offline

Joined: Thu Feb 02, 2006 1:41 pm
Posts: 1122
Location: Southern Central USA
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

?

_________________
Sincerely,
Yukiko

I know you think you understand what you thought I said but what you heard is not exactly what I meant.

Titus 2:13


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 07, 2006 7:22 pm 
Offline

Joined: Mon Feb 06, 2006 6:12 am
Posts: 93
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...


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 07, 2006 11:38 pm 
Offline

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


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 08, 2006 4:38 am 
Offline

Joined: Thu Feb 02, 2006 8:33 am
Posts: 276
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:
Test 1
{
    onID a3:i1S4:testi3
}


You will get your array with the following code:

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


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 09, 2006 6:18 am 
Offline

Joined: Fri Feb 03, 2006 6:32 am
Posts: 104
Location: Austria
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.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 09, 2006 6:56 am 
Offline
POL Developer
User avatar

Joined: Wed Jan 25, 2006 2:30 am
Posts: 405
Location: San Diego, California
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!

_________________
-Austin


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 09, 2006 7:23 am 
Offline

Joined: Mon Feb 06, 2006 6:12 am
Posts: 93
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 14 posts ] 

All times are UTC - 8 hours


Who is online

Users browsing this forum: coltain and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
Style based on FI Subice by phpBBservice.nl