Arrays in Verbot

Tips and questions about scripting your Verbot®.

Moderator: Staff

Arrays in Verbot

Postby JonC » Wed Aug 18, 2010 8:39 pm

This is sort of a "musing" on the idea, prompted by a request for array handling in "feature requests".
In standalone Verbots we've already got csv file handling.
Effectively a csv datafile is a 2D array containing x items in each of y rows.

The csv file handling can either leave the data in a single vars-variable (I call this an unsplit csv file), or it can assign a vars-variable to each row, typically [variable-name1] -> [variable-namey].

Now we can also split strings on a whole variety of characters, ones like "|" or "~" which I've used to sub-divide a csv "value".
This suggests that a 3D x,y,z ("width, height, depth") array can be represented a 2D csv file (as above), but with each "value" of the csv data containing all the z dimension values (separated by "|" say).
In other words, each csv value would represent one "depth" row of the 3D array.

To get an element of the 3D x,y,z matrix we need to specify which x (call it i), which y (call it j) and which z (call it k) we want.
In other words we want the i,j,kth element of the 3D matrix.
Now, if the whole csv file is stored in "split" form (one vars-variable per row) and if we make the naming of the variables as namei, we can immediately access the correct value in the x dimension by just operating on the ith vars-variable.
Splitting that vars-variable by "," and getting the jth element isolates the y value and a further split of the jth value by "|" isolates the z value.
Job done.

Other "jobs" like changing values are also fairly simple (the code to do {most} of it is published) as would be writing new data - the csv can be extended provided the formatting is correct.

I guess if someone was mad enough and had a brain that thought in more dimensions, then the idea can be extended to more than 3D, but does anyone want more than a 3D matrix in a Verbot?
JonC
SupremeBot
SupremeBot
 
Posts: 665
Joined: Wed Apr 02, 2008 6:34 am
Location: Leicestershire, Great Britain

Return to Scripting

Who is online

Users browsing this forum: No registered users and 1 guest