This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
pbcub1's profile picture

[Question]How do I pass an array over function arguements?

Started by pbcub1, 26 December 2012 - 07:18 AM
pbcub1 #1
Posted 26 December 2012 - 08:18 AM
^
Cozzimoto #2
Posted 26 December 2012 - 08:27 AM
do u have any code or are you trying to figure out how to get the arguments you pass in the program as soon as you run it

if so then you have to clarify a table at the top like this


tArgs = { ... }

so anything you pass in your program would be saved in a table tArgs[1] tArgs[2] etc..
pbcub1 #3
Posted 26 December 2012 - 08:38 AM
no,

while true do
eArg = { ... }
local event, eArg = os.pullEvent()
eHand(event, eArg[...])
end
--pass array to function
local function eHand(event, eArg)
--lots of secret sh**
end
Cozzimoto #4
Posted 26 December 2012 - 08:42 AM
what exactly are you trying to do?? im trying to interpret your snippet here and im not quite getting it
Doyle3694 #5
Posted 26 December 2012 - 08:49 AM
that is so unproper use

first, eHand must be declared before used. os.pullEvent that way wouldn't return a string and a table but rather 1 string and 1 string/number more proper would be


local eArg = {os.pullEvent()}
then the event is eArg[1]. Then eHand(eArg) should do the trick. Also, very important, they are TABLES!
Doyle3694 #6
Posted 26 December 2012 - 08:53 AM
also, why defuq are you using … everywhere? why would you loop it over and over again with arguments you pass? and you are emptying the table on the os.pullEvent line anyways. Also, eArg[…] will probably try to pull a table from arguments and then find a name that is equal to that table. however, names can't be tables, so you'll get an error.
pbcub1 #7
Posted 26 December 2012 - 09:00 AM
thanks, ill try it out
Cozzimoto #8
Posted 26 December 2012 - 09:12 AM
yea doyle got what i was trying to say. lol i missed that he was clearing the passed arguments within the loop that should be declared as a global variable for sure.

*Cozzy gives thumbs up of approval*