Jump to content

Checking is number.


Martyz

Recommended Posts

Sorry for double posting.

I've got this error:

[2011-01-01 22:35:27] start: Requested by Console 
[2011-01-01 22:35:27] Starting race_martyz 
[2011-01-01 22:35:27] SCRIPT ERROR: race_martyz\commands.lua:37: 'end' expected (to close 'function' at line  near 'else' 
[2011-01-01 22:35:27] WARNING: Loading script failed: race_martyz\commands.lua:37: 'end' expected (to close 'function' at line  near 'else' 
[2011-01-01 22:35:27] start: Resource 'race_martyz' started 

code:

function lotto_roll(player, amount) 
  if tonumber(amount) then 
    if(amount < 100) then 
      outputChatBox("Minimum roll amount is 100$!", player, 255, 100, 0, false) 
      return 
    end 
    if(amount > 1000) then 
      outputChatBox("Maximum roll amount is 1000$!", player, 255, 100, 0, false) 
      return 
    end 
    if(amount > getPlayerMoney(player)) then 
      outputChatBox("You have less money than you entered!", player, 255, 100, 0, false) 
      return 
    end 
    local rroll = math.random(0, 2) 
    if(rroll == 0) then 
      outputChatBox("You've spinned for " ..amount.. "$ and lost!", 255, 255, 0, false) 
      takePlayerMoney(player, amount) 
    end 
    if(rroll == 0) then 
      outputChatBox("You've spinned for " ..amount.. "$ and lost!", 255, 255, 0, false) 
      takePlayerMoney(player, amount) 
    end 
    if(rroll == 1) then 
      outputChatBox("You've spinned for " ..amount.. "$ and WON!", 255, 255, 0, false) 
      givePlayerMoney(player, amount) 
    end 
  end 
  else 
    outputChatBox("It must be number!", player, 255, 100, 0, false) 
  end 
end 
addCommandHandler("roll", lotto_roll) 

Edited by Guest
Link to comment

I know how to use else if from PAWN, just didn't think about it in lua ^^ I will try changing something to elseif and will write what's the result.

EDIT:

Problem were not in elseif, but I fixed it by my own, anyway thank you very much for helping.

Link to comment
amount = tonumber(amount) 
if amount and type(amount) == "number" then 
  -- ok 
else 
  -- not ok 
end 

tonumber() returns either number or nil, so i dont think type(amount) == "number" is necessary. unless i'm wrong ofc :3

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...