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
https://metin2.dev/topic/7565-useing-lua-table/
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
https://metin2.dev/topic/7565-useing-lua-table/#findComment-47450
Share on other sites

Don't use any images from : imgur, turkmmop, freakgamers, inforge, hizliresim... Or your content will be deleted without notice...
Use : https://metin2.download/media/add/

Please use https://metin2.download/ when uploading files smaller than 100MB, otherwise the approval will take longer due to manual upload.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • 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.