|
Fang Xianfu GURU
Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: Sat Dec 22, 2007 5:20 pm
[2.18 Lua] Bad return from zs.param() |
zs.param() is returning 0 when a number that doesn't exist is referenced - not a very good return since a parameter could potentially be the number 0. The following code will work, for example
local i, params = 1, {}
while zs.param(i)~=0 do
table.insert(params,zs.param(i))
i=i+1
end |
but obviously only if none of the legitimate parameters are 0. |
|
|
|
rck Novice
Joined: 26 Oct 2005 Posts: 32 Location: California
|
Posted: Sat Dec 22, 2007 8:02 pm |
Hmm, true, I guess it should return nil instead?
But you could doublecheck zs.params() (or whatever the func is that tells you the count of params). |
|
|
|
Fang Xianfu GURU
Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: Sat Dec 22, 2007 9:56 pm |
There isn't actually a function that returns the parameter count - I guess it's assumed that if you care about the parameter count, you'll have decided how many parameters you're going to have for an alias and fixed the number, and if you don't care you'll use the catch-all params function.
What'd be really sweet is if that whole bit of code (with potentially many zscript function calls) could be simplified to something like local params = zs.param. |
|
|
|
Vijilante SubAdmin
Joined: 18 Nov 2001 Posts: 5182
|
Posted: Sat Dec 22, 2007 10:20 pm |
Unless I am off my rocker again you do have a function that tells you how many parameters there are, %numparam. Which should be accessible as zs.numparam() or zs.func.numparam().
|
|
_________________ The only good questions are the ones we have never answered before.
Search the Forums |
|
|
|
Fang Xianfu GURU
Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: Sat Dec 22, 2007 10:34 pm |
My excuse for not remembering that is that I woke up from a nap 10 minutes before writing that post. A dire lapse, it really is. Good call. Here's a better version:
local params = {}
for i=1,zs.numparam do
table.insert(params,zs.param(i))
end |
Interestingly, zs.numparam isn't a function at all, but a direct number value. Very strange.
It'd still be nice if zs.param had a proper return, though, for hopefully obvious reasons.
#if (%1) {target = %1};attack @target |
For example. |
|
|
|
|
|