ScriptUO

Official ScriptUO EasyUO Scripts => Script Snippets => Topic started by: TrailMyx on June 09, 2008, 12:16:58 PM

Title: TrailMyx's multi-dimensional Array Handler
Post by: TrailMyx on June 09, 2008, 12:16:58 PM
Here's the subs:
Code: easyuo
  1. ; %1 = Arrayname
  2. ; %2 = Value to add
  3. ; %3 = index 1
  4. ; %4 = index 2
  5. ; ...
  6. sub AddToArray
  7.   namespace push
  8.   namespace local Array , _ , %1
  9.   set !var
  10.   for !index 3 %0
  11.      set !var % . !index , _ , !var
  12.   set ! . !var %2
  13.   namespace pop
  14. return
  15. ; %1 = Arrayname
  16. ; %2 = index 1
  17. ; %3 = index 2
  18. ; ...
  19. sub GetFromArray
  20.   namespace push
  21.   namespace local Array , _ , %1
  22.   set !var
  23.   for !index 2 %0
  24.      set !var % . !index , _ , !var
  25.   set #RESULT ! . !var
  26.   namespace pop
  27. return #RESULT
  28.  

Here's some test code:

Code: easyuo
  1. gosub AddToArray myarray 34 5 5 ; myarray[5][5] = 34
  2. gosub GetFromArray myarray 5 5  ; gets value at myarray[5][5]
  3. stop
  4.  
Title: Re: TrailMyx's multi-dimensional Array Handler
Post by: Paulonius on December 04, 2009, 06:41:17 PM
TM,

I would love it if at some point you have time and inclination to write up a tutorial on how to use these.  Just figured I would let you know there would be an audience...

-P
Title: Re: TrailMyx's multi-dimensional Array Handler
Post by: TrailMyx on December 04, 2009, 07:17:04 PM
Hmm, well there's not alot to write about really.  An array is an array.  If you scrutinize the sample I gave:

Code: [Select]
gosub AddToArray myarray 34 5 5 ; myarray[5][5] = 34
gosub GetFromArray myarray 5 5  ; gets value at myarray[5][5]

I'm calling out an array named "myarray".  From the arguments, you can see I'm putting a value of "34" into index [5]][5].  The next line is just recalling the value.

I guess the one thing I can point out is this is a multidimensional array, so you could potentially have limitless indexes.
Title: Re: TrailMyx's multi-dimensional Array Handler
Post by: Paulonius on December 04, 2009, 08:19:23 PM


Quote
Hmm, well there's not alot to write about really.  An array is an array.

This tells me that you are too far away from not knowing what arrays are to explain them to me, which makes me laugh at myself for asking.  I am pretty sure I had a book on BASIC that had something like Chapter 3: Arrays...   Unfortunately that was 1984 and I didn't do anything remotely related to programming between then and when I started logging into SUO earlier this year...

When I have time I will find an explanation from some remedial text book and dovetail it into this thread for the completely ignorant... like me.  I am pretty sure I am working on a script that really wants an array or two and I need to turn myself into someone who can give it what it wants...
Title: Re: TrailMyx's multi-dimensional Array Handler
Post by: NObama on December 04, 2009, 08:23:07 PM
Multi-dimensional...like the negative zone?

 8)
Title: Re: TrailMyx's multi-dimensional Array Handler
Post by: Endless Night on December 04, 2009, 08:45:50 PM
Well think of a 2 dimensional array as your screen.  To locate a pxiel on your screen you use x,y postioning... So the entire screen is a mutli (2) dimensional array.

So tms example could be

gosub AddToArray myscreen %PixelColor %x  %y
gosub GetFromArray mycreen %x %y


Now a 3rd dimensional array is the same as the pinpointing a location on the UO map.. you have X,Y,Z

a 4th dimensional array could be ....

bla bla bla...
Title: Re: TrailMyx's multi-dimensional Array Handler
Post by: TrailMyx on December 05, 2009, 04:23:08 AM
This tells me that you are too far away from not knowing what arrays are to explain them to me, which makes me laugh at myself for asking. 

Lol!  Sorry Paul.  I guess arrays are one of those fundamentals, but I forget that even those fundamentals sometimes are hard to understand.

Probably the best example I can think of when I think of arrays are to think of your multiplication table (example of a 2 dimensional array)

Code: easyuo
  1. ; set up your times tables
  2. for %x 1 12
  3. {
  4.   for %y 1 12
  5.   {
  6.     set %times %x * %y
  7.     gosub AddToArray times_table %times %x %y
  8.   }
  9. }
  10.  
  11. gosub GetFromArray times_table 11 12
  12. display ok 11 times 12 is , #SPC #RESULT
  13.  
  14. gosub GetFromArray times_table 5 7
  15. display ok 5 times 7 is , #SPC #RESULT
  16.  
  17. gosub GetFromArray times_table 8 9
  18. display ok 8 times 9 is , #SPC #RESULT
  19.  
  20. stop
  21. ; %1 = Arrayname
  22. ; %2 = Value to add
  23. ; %3 = index 1
  24. ; %4 = index 2
  25. ; ...
  26. sub AddToArray
  27.   namespace push
  28.   namespace local Array , _ , %1
  29.   set !var
  30.   for !index 3 %0
  31.      set !var % . !index , _ , !var
  32.   set ! . !var %2
  33.   namespace pop
  34. return
  35. ; %1 = Arrayname
  36. ; %2 = index 1
  37. ; %3 = index 2
  38. ; ...
  39. sub GetFromArray
  40.   namespace push
  41.   namespace local Array , _ , %1
  42.   set !var
  43.   for !index 2 %0
  44.      set !var % . !index , _ , !var
  45.   set #RESULT ! . !var
  46.   namespace pop
  47. return #RESULT
  48.