Re: Randomizing from a list of variables
Status: Alpha
Brought to you by:
cwalther
From: James C. W. <jfc...@ya...> - 2011-07-07 05:06:15
|
Thank you Urs! That worked spendidly, thank you. -James --- On Wed, 6/29/11, Urs Holzer <ur...@an...> wrote: From: Urs Holzer <ur...@an...> Subject: Re: Randomizing from a list of variables To: pip...@li... Date: Wednesday, June 29, 2011, 2:42 AM Hi James James C. Wilson wrote: > Thanks! I'm afraid I don't know what an array is, however...Could you > explain if possible? A value in Lua can be of type table. A table actually associates a key (which is also just a value) to another value. Of course it can have many entries. Say foo is a table, then foo["bar"] returns the value associated to the key "bar". Using foo["bar"] = 1 Sets the value associated to the key "bar" to 1. In other words, a table stores values which you can read and set by key. Lua does not know arrays as other programming languages do, since in Lua, an array is realized by a table which only has integers as keys. So if I say "array" here, I mean actually a table which has only integers as keys. Example: local sound = {} -- create a table sound[1] = sound1 -- sound now associates the value sound1 to the key 1 sound[2] = sound2 -- sound now associates the value sound2 to the key 2 sound[3] = sound3 -- sound now associates the value sound3 to the key 3 local n = 2 -- Store value 2 in the variable n sound[n] -- Returns the value associated to the key 2 You can read up more about tables here: http://www.lua.org/pil/2.5.html Description from http://en.wikipedia.org/wiki/Associative_array: An associative array (also associative container, map, mapping, dictionary, finite map, table, and in query-processing an index or index file) is an abstract data type composed of a collection of unique keys and a collection of values, where each key is associated with one value (or set of values). The operation of finding the value associated with a key is called a lookup or indexing, and this is the most important operation supported by an associative array. The relationship between a key and its value is sometimes called a mapping or binding. For example, if the value associated with the key "bob" is 7, we say that our array maps "bob" to 7. Associative arrays are very closely related to the mathematical concept of a function with a finite domain. As a consequence, a common and important use of associative arrays is in memoization. Hope this helps Greetings Urs ------------------------------------------------------------------------------ All of the data generated in your IT infrastructure is seriously valuable. Why? It contains a definitive record of application performance, security threats, fraudulent activity, and more. Splunk takes this data and makes sense of it. IT sense. And common sense. http://p.sf.net/sfu/splunk-d2d-c2 _______________________________________________ Pipmak-Users mailing list Pip...@li... news://news.gmane.org/gmane.games.devel.pipmak.user https://lists.sourceforge.net/lists/listinfo/pipmak-users |