PtokaX forum

Archive => Archived 4.0 boards => Help with Lua 4 scripts => Topic started by: Guibs on 31 January, 2004, 23:39:13

Title: dostring function & nil value,.....
Post by: Guibs on 31 January, 2004, 23:39:13
Hi all,

Brrrr..... little problem, there....

Using > dostring(arg.."="..val) <
we can assign a value(val) to a parameter (arg),...

But,...
If we want that parameter get the ' nil value ' (to disable the parameter),, then... how can we get the nil result ???
I've tried:
---
val = nil
dostring(arg.."="..val)
---
doesn't work, lol... ^^

Thks in adance for your help... :)

l8tr,, ;)
Title:
Post by: pHaTTy on 01 February, 2004, 01:04:32
if you mean send to user the value equals nil use brackets val = "nil"

otherwise i dont understand what you mean  ?(
Title:
Post by: Guibs on 01 February, 2004, 01:48:14
Hi there,,

well,.. it was to assign a nil value on a parameter/string,... :)
We have speak about on Msn,... but I take an example to be more clear,...
---
!set beertime on
---
then, if you use the function:
---
if arg2 == "on" then val = 1 end
dostring(arg.."="..val)
---
it gives:
"beertime" = 1
---
But i would like a way to assign a nil value to arg,... instead of using such function as:
---
if arg == "beertime" and arg2 == "off" then"beertime" = nil end
---
hope it's more clear...

l8tr,, ;)
Title:
Post by: c h i l l a on 01 February, 2004, 02:15:06
dunno maybe

dostring(arg.."=nil)

but else it clear that the error comes up, cause LUA will look for the variable val, and if you set a variable = nil then it is release = deleted, nada, nirvana what ever, its not there anymore.
Title:
Post by: NotRabidWombat on 01 February, 2004, 07:18:34
The same way to do proper debugging.
Use: or "nil"

dostring(arg.."="..(val or "nil"));

if val is equal to nil the or condition kicks in and the non-nil string "nil" is returned in its place. This is very usefull when you want to test values/commands in scripts.

SendToAll(sBotName, val or "nil");

P.S. - I reread your comment and you appear to be using strings. Don't forget to do formating with the val that you are passing (make sure they are sending you some cooked data).

-NotRabidWombat