I
Icy
Guest
Here is a talkaction I quickly wrote up:
So if this talkaction was executed like this:
It should return the message:
The thing is.. to access the number that was set as a parameter I have to set it as a "global" variable outside of the onSay function.
My question to you: Is there any way to pass it as a parameter instead?
Lua:
--@author: Icy
--@date: January 17th, 2011
--@purpose:
-- Provide an example of accessing a pseudo-global variable
-- declare variables
local number
-- function to be called on execution of talkaction
function onSay(cid, words, param, channel)
if(setVariables(param)) then
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, 'Starting...')
local result = doMath()
else
return doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED, 'Variables not set.')
end
return doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, 'The result is: ' .. result)
end
-- multiplies the previously set variable by 3
function doMath()
local ret = number * 3
return ret
end
-- function to set variables
function setVariables(param)
if not(isNumber(param)) then
return false
else
number = tonumber(param)
return true
end
So if this talkaction was executed like this:
/math 5
It should return the message:
(the product of 5 * 3)The result is: 15
The thing is.. to access the number that was set as a parameter I have to set it as a "global" variable outside of the onSay function.
My question to you: Is there any way to pass it as a parameter instead?