[KIXTART] Arrays, hoe werkt dat?

Pagina: 1
Acties:
  • 149 views sinds 30-01-2008
  • Reageer

  • collin
  • Registratie: Februari 2000
  • Laatst online: 03-09 14:37

collin

Who da man !!

Topicstarter
Ik heb een vraagje over Kixtart (Loginscript interpreter, http://kixtart.org ). Je kan er arrays mee gebruiken, maar ik kom er maar niet achter hoe! In de handleiding van Kixtart staat dit:
Arrays
KiXtart supports single dimension arrays. Arrays allow you to refer to a series of variables by the same name and to use a number (an index) to tell them apart. This helps you create smaller and simpler code in many situations, because you can set up loops that deal efficiently with any number of cases by using the index number. Arrays have both upper and lower bounds, and the elements of the array are contiguous within those bounds. Because KiXtart allocates space for each index number, avoid declaring an array larger than necessary.

Unlike normal variables, arrays must be declared explicitly before they can be used.

When declaring an array, follow the array name by the upper bound in square brackets. The upper bound cannot exceed 2,147,483,647.

Examples:

Dim $Counters[14] ; explicit declaration
Dim $Sums[20] ; explicit declaration
$NewArray = 10,20,30 ; implicit declaration
$NewArray = "A1","B2","C3" ; implicit declaration
The first declaration creates an array with 14 elements, with index numbers running from 0 to 13. The second creates an array with 20 elements, with index numbers running from 0 to 19. The third, implicit, declaration creates an array with 3 elements, with index numbers running from 0 to 2.

All elements of an array that has been declared explicitly have the same type: integer. Individual elements of an array can subsequently be changed to the string type (just as any other variable) simply by assigning a string expression to them.

Note: Unlike regular variables, arrays can not be used inside strings and can also not be assigned a value on the command line.
That's it! Ik heb die array gedeclareerd aan het begin van het script, zoals het staat aangegeven, maar hoe krijg ik nou een waarde in die Array? Ik heb namelijk 10 paren variabelen die ik wil laten uitvoeren. Zeg maar $share1 hoor bij $letter1, $share2 bij $letter2, etc. Nou wil ik dus een array maken voor $share[x] en voor $letter[x]. En dan zoiets laten uitvoeren:
code:
1
2
3
4
5
6
$x = 1

WHILE $x < 10
   use $letter[$x] "$share[$x]"
   $x = $x + 1
LOOP

Zoiets dus. Als ik gewoon intik:
$share[1] = "\\SERVER\DATA"
Dan hangt kixtart op een dr. watson! Arrays zullen ongetwijfeld wel op veel dingen heel erg op elkaar lijken in de talen onderling, dus ik hoop dat iemand me kan vertellen, of een site kan geven hoe die klote arrays werken :) Ik heb me het schompes gezocht nl..

Mijn iRacing profiel