• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Solved Table loop.. why do I need another 'end'?

  • Thread starter Thread starter Xikini
  • Start date Start date
X

Xikini

Guest
Server version is irrelevant for this question. :p

I am trying to implement a 'chance to win' within my table, so I can easily change the chance of getting an item, depending on how many different items there are to win, however, for some reason the 'local number' is requiring an end, and I don't understand why that is.

Can someone explain where the end is supposed to go?

Thanks. :D

Code:
local prizes = {
   [1] = {min = 1, max = 10, item_id = 1111, amount = 1}, -- 10 percent chance
   [2] = {min = 11, max = 40, item_id = 1111, amount = 1}, -- 30 percent chance
   [3] = {min = 41, max = 100, item_id = 1111, amount = 1} -- 60 percent chance
}

function onUse(cid, item, frompos, item2, topos)
   local number = (math.random(1,100) 
   for i = 1, #prizes do  -- #prizes.min, #prizes.max
     if number >= prizes[i].min and number <= prizes[i].max then
       doPlayerAddItem(cid, prize[i].item_id, prize[i].amount)
       break
     end
   end
return true
end
 
It's the for loop that needs to close with end.
_HdAzoZ5T.png
I understand that.. but the script will error according to notepad++. :P
a0ZM8zo.png
 
Thanks. :p
Btw, is there a way for normal members to delete posts other then reporting them?
Premium members can delete their own posts, other members have to report their post and ask for deletion.
It doesnt matter at all..
You don't even have to use return true.
If you don't add return true in action scripts people will get a cancel message with "You cannot use this object." when using the item.
 
Last edited:
It doesnt matter at all..
You don't even have to use return true.
Technically you don't have to.. but wouldn't it create 'garbage' until lua does the next check to remove?
Premium members can delete their own posts, other members have to report their post and ask for deletion.
Ah, I was wondering that. Because I remember seeing it before, but I guess I'm not 'premium' anymore. :P
 
This is not true for every callback. Some of them aren't checked for the return value.
Still good practise, ex. movements have never needed the return value, since it just calls the function.
But there are plans to be able to return a move by returning false in a movement script.
Ref: https://github.com/otland/forgottenserver/wiki/Roadmap-1.2

onStepIn/onStepOut return value should matter, return false should cancel the step, default to return true
 

Similar threads

V
  • Question Question
Replies
6
Views
443
verdehile95
V
Back
Top