how to show the whole Array?
 

News:

29 December 2022 - PtokaX 0.5.3.0 (20th anniversary edition) released...
11 April 2017 - PtokaX 0.5.2.2 released...
8 April 2015 Anti child and anti pedo pr0n scripts are not allowed anymore on this board!
28 September 2015 - PtokaX 0.5.2.1 for Windows 10 IoT released...
3 September 2015 - PtokaX 0.5.2.1 released...
16 August 2015 - PtokaX 0.5.2.0 released...
1 August 2015 - Crowdfunding for ADC protocol support in PtokaX ended. Clearly nobody want ADC support...
30 June 2015 - PtokaX 0.5.1.0 released...
30 April 2015 Crowdfunding for ADC protocol support in PtokaX
26 April 2015 New support hub!
20 February 2015 - PtokaX 0.5.0.3 released...
13 April 2014 - PtokaX 0.5.0.2 released...
23 March 2014 - PtokaX testing version 0.5.0.1 build 454 is available.
04 March 2014 - PtokaX.org sites were temporary down because of DDOS attacks and issues with hosting service provider.

Main Menu

how to show the whole Array?

Started by RobinHood, 04 February, 2004, 10:32:05

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

RobinHood

is it possible to show the whole array, perhaps sorted?

for example i've something like this:

userArray[user.sName]=arg

can i show all items sorted by username ?
can i show all items sorted by arg?
if it's not possible, can i show all unsorted?
can i search f?r args?

perhaps someone can help?

thx

c h i l l a

you can only sort associative tables.

so first you need to create a associatve table from you non associative one

then sort it for what you need.
then read it out.

if your table is very big then you should also use a search tool for searching non associative tables

check for thread "table search"

so it is possible :)

RobinHood

thx for your reply, but your answer won't help me :-(

i've scripted a hub script for my hub, but i still haven't understood tables :-(

i don't know their function and i d don't know how to create a table :-(

i can create an array and i can show arg if i've the username, but i cannot show all items.

but perhaps sometimes i will understand this., too ;-)

i think my script has to wait until this moment :-(

NotRabidWombat

#3
Hi,

I'm guessing you've programming in some C like language that implements arrays by a sequence of the variables that are the same type.

In lua, arrays have been replaced with tables. Tables can be used like arrays with 1 based number indexes. They can also be used like associative arrays (or a hash table). These associative arrays take in string indexes to find your desired element. The element the index represents can be anything and can be different for each element in the table.

So you can see, there is a real difficult time sorted an associative array, which you are using. The best way to do it is to have two tables. The first is like the one you have. You use a user name or string argument to index. You have it point to a table that contains the data you want (tables are the only things you can really point to and have multiple pointers to the same table since they are always passed by reference).
The table you are pointing to will contain the argument you used to index and the value you want to store. Now you can copy these table elements into a second table that uses number indexes. Use the sort function to sort it and now you have exactly what you want.

If you'd like a working example, I do the same thing in my JumbleFever script.

If you'd just want to view the entire contents of a table, you can use the foreach function. Go here: http://www.lua.org/manual/4.0/manual.html for more information.

-NotRabidWombat


I like childish behavior. Maybe this post will be deleted next.

RobinHood

thx NotRabidWombat,

i found another thread :-)

now i can show all items

an i wrote a code to search for args

your description about sorting sounds difficult *g*

so i think i will make it unsorted, because i can search for args :-))

SMF spam blocked by CleanTalk