Jump to content

Getting data from table using loop


Mann56

Recommended Posts

Hey guys,

I might seem a noob but i can't get the co-ordinates out of the table to create a marker.

Server file :

markercords = {  
                {1945.20874, -1778.62756, 13.39060}, 
                {1944.33765, -1773.98657, 13.39060}, 
                {1944.09851, -1771.35437, 13.39060}, 
                {1944.29260, -1767.30762, 13.38281}, 
              } 
               
addEventHandler("onResourceStart",resourceRoot, function () 
         for i , marker in pairs(markercords) do 
         createMarker(markercords,"cylinder",2,255,255,0,100) 
         end 
         end 
         ) 

The problem is that when i execute the code, all three cords, go in one argument, i tried with x,y and z variables too but of no use : < Please help

Link to comment

Try it.

markercords = { 
                {1945.20874, -1778.62756, 13.39060}, 
                {1944.33765, -1773.98657, 13.39060}, 
                {1944.09851, -1771.35437, 13.39060}, 
                {1944.29260, -1767.30762, 13.38281} 
              } 
              
addEventHandler("onResourceStart",resourceRoot, function () 
         for i , marker in pairs(markercords) do 
         createMarker(markercords,"cylinder",2,255,255,0,100) 
         end 
         end 
         ) 

Link to comment

It should works.

local markercords = {  
 [1]={1945.20874, -1778.62756, 13.39060}, 
 [2]={1944.33765, -1773.98657, 13.39060}, 
 [3]={1944.09851, -1771.35437, 13.39060}, 
 [4]={1944.29260, -1767.30762, 13.38281} 
} 
  
addEventHandler("onResourceStart",resourceRoot,  
function () 
for i=1, #markercords do 
    local x , y , z = markercords[i][1], markercords[i][2], markercords[i][3] 
    local Marker = createMarker(x , y , z,"cylinder",2,255,255,0,100) 
  end 
end) 
  

Link to comment
markercords = { 
     {1945.20874, -1778.62756, 13.39060}, 
     {1944.33765, -1773.98657, 13.39060}, 
     {1944.09851, -1771.35437, 13.39060}, 
     {1944.29260, -1767.30762, 13.38281}, 
} 
              
addEventHandler("onResourceStart",resourceRoot, function() 
     for i, pos in ipairs(markercords) do 
          local x,y,z = unpack(pos) 
          createMarker(x,y,z,"cylinder",2,255,255,0,100) 
     end 
end) 

Link to comment

what? Try this code :P

  
local markercords={ 
    {1945.20874, -1778.62756, 13.39060}, 
    {1944.33765, -1773.98657, 13.39060}, 
    {1944.09851, -1771.35437, 13.39060}, 
    {1944.29260, -1767.30762, 13.38281} 
} 
                  
addEventHandler("onResourceStart", resourceRoot, function() 
    for i, data in pairs(markercords) do 
        local marker=createMarker(data[1], data[2], data[3], "cylinder", 2, 255, 255, 0, 100) 
    end 
end) 
  

Link to comment
markercords = { 
     {1945.20874, -1778.62756, 13.39060}, 
     {1944.33765, -1773.98657, 13.39060}, 
     {1944.09851, -1771.35437, 13.39060}, 
     {1944.29260, -1767.30762, 13.38281}, 
} 
              
addEventHandler("onResourceStart",resourceRoot, function() 
     for i, pos in ipairs(markercords) do 
          local x,y,z = unpack(pos) 
          createMarker(x,y,z,"cylinder",2,255,255,0,100) 
     end 
end) 

and what's wrong with mine?

local markercords = { 
 [1]={1945.20874, -1778.62756, 13.39060}, 
 [2]={1944.33765, -1773.98657, 13.39060}, 
 [3]={1944.09851, -1771.35437, 13.39060}, 
 [4]={1944.29260, -1767.30762, 13.38281} 
} 
  
addEventHandler("onResourceStart",resourceRoot, 
function () 
for i=1, #markercords do 
    local x , y , z = markercords[i][1], markercords[i][2], markercords[i][3] 
    local Marker = createMarker(x , y , z,"cylinder",2,255,255,0,100) 
  end 
end) 

Edited by Guest
Link to comment

Also,another way

local markercords = { 
 [1]={mx=1945.20874, my=-1778.62756, mz=13.39060}, 
 [2]={mx=1944.33765, my=-1773.98657, mz=13.39060}, 
 [3]={mx=1944.09851, my=-1771.35437, mz=13.39060}, 
 [4]={mx=1944.29260, my=-1767.30762, mz=13.38281} 
} 
addEventHandler("onResourceStart",resourceRoot, 
function () 
    for index, data in pairs(markercords) do 
        local marker = createMarker(data.mx, data.my, data.mz-1, "cylinder", 2, 255, 255, 0, 100) 
    end 
end) 

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...