Hello, I am currently trying to make enemy typing in a game I am making. I am using HardonCollider (HC) to construct polygons for enemy shapes, and for some reason it hates it when I try to pass a table as an argument, instead of a list of raw numbers (in the form func(1,2,3,4,5,6,etc.)). Is there a way to write a function that returns all the values of a table in the form of a,b,c,d,e,f,etc. ?
Something like:
function foo(t)
return t[1], t[2], t[3], t[4], t[5], t[6], etc.
end
But without having to write out a million billion table references.
Returning a List of Variables (x, y, z, ...) From a Table
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- Rhinoceros
- Prole
- Posts: 35
- Joined: Mon Jun 11, 2012 2:59 am
- Location: Under the Floorboards
Re: Returning a List of Variables (x, y, z, ...) From a Tabl
Code: Select all
unpack( t )
Re: Returning a List of Variables (x, y, z, ...) From a Tabl
For completeness, here is another way that you really shouldn't use because it is way slower and also less readable than unpack (but the technique is good to know anyway):
Code: Select all
function my_unpack_helper(n, t, ...)
if n == 0 then -- end recursion
return ...
end
return my_unpack_helper(n-1, t, t[n], ...) -- observe the power of tail recursion!
end
function my_unpack(t)
return my_unpack_helper(#t, t)
end
Who is online
Users browsing this forum: No registered users and 99 guests