Newbee & Tables
 

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

Newbee & Tables

Started by gaiza, 27 May, 2005, 22:56:11

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

gaiza

Hello, this is my first post, so hello everybody.

My question is:

I have a fuction that return a table
prototype is as follow :

TheFuncProvided() -- (args - 0, results - 1 (table of key(string).value(boolean))

so to get the result i wrote this :

Table = TheFuncProvided()

if Table then
      Val = Table.astringaskey
   
      if Val then
             --do somthing
      end
end


As resukt Val is always nil, but table is not empty.

What i'm doing wrog ?

Thanks for your help.

gaiza

Well, nobody know anything about arrays ?

Dessamator

hmm, its probably because ppl are confused by ur "problem", in lua arrays are more or less like tables,


to assign a value to a table in lua u do it more or less like this :

table["stuff"] = 1


to read a key from a table u do it more or less like this:

val =table.stuff , or
val =table["stuff"]


or u can use a loop to acess the info in a table something like e.g:

local temp,temp2 =nil,nil
for index,value in table do
temp =temp.."index "
temp2 =temp2.."value "
end

P.S. u cant just assign a function to a table, unless a function returns a value which u can add to a table !
hope it helps with ur dilema !
Ignorance is Bliss.

plop

here's a example script 2 give you an idea of what you want 2 do.
!this and !that work as main chat commands and are called from a table.
the way you were trying allready failed on TheFunctionProv, as that isn't how you declare a function in lua.
and using an array for these this isn't handy, you would always have 2 loop the array, while tables can be hashed.
and like dessamator said, array's are tables in lua which are indexed by numbers.
for example:
Array = {var1, var2, var3, var4}
is inside lua
Array = {1=var1, 2=var2, 3=var3, 4=var4}

here's the example script for functions inside tables.
tTable = {
	["this"] = function(var1, var2)
		SendToAll("botje", "doing this")
		return 1
	end,

	["that"] = function(var1, var2)
		SendToAll("botje", "doing that")
		return 1
	end,
}

function ChatArrival(user, data)
	local s,e,sCmd = string.find(data, "%b<>%s+%p(%S+).*|")
	if sCmd and tTable[sCmd] then
		if tTable[sCmd](user, data) then
			return 1
		end
	end
end

if you want more examples then check my freshstuff and texter series or zcrazy.
these all use functions which are stored in tables.

plop
http://www.plop.nl lua scripts/howto\'s.
http://www.thegoldenangel.net
http://www.vikingshub.com
http://www.lua.org

>>----> he who fights hatred with hatred, drives the spreading of hatred <----<<

gaiza

Thanks gys, i'll check if ican get it work.

Thanks again, i'll keep in touch

SMF spam blocked by CleanTalk