Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD General Discussion
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: 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.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
rck
Novice


Joined: 26 Oct 2005
Posts: 32
Location: California

PostPosted: 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).
Reply with quote
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: 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.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5182

PostPosted: 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
Reply with quote
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: 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.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD General Discussion All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

© 2009 Zugg Software. Hosted by Wolfpaw.net