Posted by
| Nick Gammon
Australia (23,070 posts) Bio
Forum Administrator |
Message
| Yes, it's possible. Virtually anything is possible.
As an example, take your code here:
def SkillImprove(TriggerName, trig_line, wildcards):
#Concatonate all the variables passed by the MUSHclient
vName = ''.join([wildcards[x] for x in range(len(wildcards)-1)])
#Replace invalid characters with other characters to store as variables
vName = vName.replace(' ', '_').replace('\'', '').replace('-', '_').replace('#', '_')
#If the variable doesn't currently have a value give it
#the value of 1, else increment it by 1
if not world.GetVariable(vName):
vValue = 1
else:
vValue = int(world.GetVariable(vName)) + 1
#Display in the command window the improvement message
#with the corresponding number of improvements added in
world.SetVariable(vName, str(vValue))
world.ColourTell('#00FFFF', '', '* You think your ' + str(vName))
world.ColourTell('#FFFFFF', '', ' [')
world.ColourTell('#FF0000', '', str(vValue))
world.ColourTell('#FFFFFF', '', '] ')
world.ColourNote('#00FFFF', '', 'skill has improved. *' )
Would look roughly like this:
function SkillImprove(TriggerName, trig_line, wildcards)
--Concatonate all the variables passed by the MUSHclient
vName = table.concat (wildcards, '')
--Replace invalid characters with other characters to store as variables
vName = vName:gsub(' ', '_'):gsub('\'', ''):gsub('-', '_'):gsub('#', '_')
--If the variable doesn't currently have a value give it
--the value of 1, else increment it by 1
if not GetVariable(vName) then
vValue = 1
else
vValue = tonumber(GetVariable(vName)) + 1
end -- if
--Display in the command window the improvement message
--with the corresponding number of improvements added in
SetVariable(vName, vValue)
ColourTell('#00FFFF', '', '* You think your ' .. vName)
ColourTell('#FFFFFF', '', ' [')
ColourTell('#FF0000', '', vValue)
ColourTell('#FFFFFF', '', '] ')
ColourNote('#00FFFF', '', 'skill has improved. *' )
end -- function SkillImprove
- In Lua functions are defined with "function" not "def".
- Functions end with "end".
- "If" statements need a "then" rather than a colon, and end with a "end".
- You don't need "world." in front of world (MUSHclient) functions.
- Lua uses "elseif" rather than "elif".
- Comments start with "--" rather than "#"
- Concatenation of strings is done with ".." rather than "+".
I'll leave you to handle the rest. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|