Jump to content

Recommended Posts

  • Premium

hallo

 

what is the wrong

local data01 = {
    19, 29, 39, 49, 59,
}
for i = 1,data01[1],1 do
    if item.vnum == data01[1+1*(i-1)] then
        mount_levelup.upgrade_mount(50067,2)
    else
        say(gameforge.training_mount._63_say)
    end
end

If you're going to do something, then do it right.

Link to comment
Share on other sites

You're getting out of the index with this code!

Your for loop doesn't look correct and therefore results in this behaviour. What you're doing is:

for i = 1, data01[1], 1 do

Which means exactly this:

for i = 1, 19, 1 do

So the loop will go from 1 to 19, but the table only has 5 entries. Now we can look at the code:

if item.vnum == data01[1+1*(i-1)] then

In which case is the loop out of index? It's when 1+1*(i-1) > 5

So in your case it'd be at the 6th execution. That's the point where i=6 and the solution would be: 1+1*(6-1) > 5 and yes, 1+5 > 5

 

What you may wanted to do was this:

for i = 1, table.getn(data01), 1 do

This will only iterate through the table until it reaches the maximum. Also the Computation doesn't make sense. Why aren't you just using

if item.vnum == data01[ i ] then

instead of your code?

Edited by Alina
  • Love 1
Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

Announcements



×
×
  • Create New...

Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.