0


Please can any say me what is wrong on this simple LUA script...its something bad in the parse...

addhook("break","money") 
function money(x,y)
if x+y then do
    parse("setmoney "..id.." "..player(id,"money")+100)
      end
   end  
end
flag offensive
asked 2010-10-05 12:33:56.840885
1
add comment
1 Answers:
0


Problem #1: You have an extra block in your code. In order to maintain the notion of code that are only executed under certain conditions, Lua uses the following notation:

start of block
    [code]
end

Where you can replace start of block with one of:

  • for [condition] do
  • while [condition] do
  • if [condition] then
  • function name
  • do

In this manner of thinking, you can check whether your code is buggy by counting the number of ends and the number of start of blocks within your code.

In your case, you have the following start of blocks:

  • function money(x,y)
  • if x+y then
  • do

Note how do is embedded within the if condition, making it difficult to detect the problem? The non-confusing syntax would then be:

function money(x,y)
    if x+y then
        parse("setmoney "..id.." "..player(id,"money")+100)
    end  
end

Problem #2: An if statement treats everything as conditionally true except for false and nil. Hence, x+y will always evaluate to true, regardless of its value.

  • false - false
  • nil - false
  • "true" - true
  • 'false'- true
  • 0 - true
  • 1 - true

You can get around this by testing for the equality of a certain value with respect to another:

if 1+2 == 3 then
    print("The world makes sense again...")
end
permanent link | flag offensive
answered 2010-10-05 16:00:39.336425
41
add comment
Your answer:
You are now not logged in but you can answer first and then login
toggle preview



Tags:

× 5
× 1

Asked: 1 year, 7 months ago

Seen: 1,039 times

Last updated: 1 year, 7 months ago

Made with Django.