Jump to content

Table problem


scratcher911

Recommended Posts

Posted

I have problem with tables. When I make marker only one marker works. all should work but IDK why it doesn't.

Here's my code;

  
local jobs =  
{ 
{"Police Officer",1547.06470, -1681.80249, 13.55873, 0, 100, 255}; 
{"Paramedic",1178.41431, -1328.58850, 14.11890, 0, 255, 255}; 
} 
  
for _, job in ipairs (jobs) do 
jobMarker = createMarker(job[2], job[3], job[4], "cylinder", 1.5, job[5], job[6], job[7]) 
end 
  
addEventHandler("onClientMarkerHit", jobMarker, 
function() 
--CODE HERE 
end 
) 
  

Posted

You should use

unpack(var) 

local jobs = 
{ 
{"Police Officer",1547.06470, -1681.80249, 13.55873, 0, 100, 255}; 
{"Paramedic",1178.41431, -1328.58850, 14.11890, 0, 255, 255}; 
} 
  
  
for _, job in ipairs (jobs) do 
local v1, v2, v3, v4, v5, v6, v7 = unpack (job)  
jobMarker = createMarker(v2,  v3, v4, "cylinder", 1.5, v5, v6, v7) 
end 
  
addEventHandler("onClientMarkerHit", jobMarker, 
function() 
--CODE HERE 
end 
) 

Posted

I am afraid I do not know then, delete what I told you to write. I'm sorry

Btw only one will work because you make two fors, and the last one gets inside the variable.

The first won't get an event.

Posted
local jobMarker = {} 
local jobs =  
{ 
{"Police Officer",1547.06470, -1681.80249, 13.55873, 0, 100, 255}, 
{"Paramedic",1178.41431, -1328.58850, 14.11890, 0, 255, 255} 
} 
  
for i=1,#jobs do 
jobMarker[i] = createMarker(jobs[i][2], jobs[i][3], jobs[i][4], "cylinder", 1.5, jobs[i][5], jobs[i][6], jobs[i][7]) 
addEventHandler("onClientMarkerHit",jobMarker[i],myFunction) 
end 
  
function myFunction() 
--CODE HERE 
end 

Posted
You should use
unpack(var) 

local jobs = 
{ 
{"Police Officer",1547.06470, -1681.80249, 13.55873, 0, 100, 255}; 
{"Paramedic",1178.41431, -1328.58850, 14.11890, 0, 255, 255}; 
} 
  
  
for _, job in ipairs (jobs) do 
local v1, v2, v3, v4, v5, v6, v7 = unpack (job)  
jobMarker = createMarker(v2,  v3, v4, "cylinder", 1.5, v5, v6, v7) 
end 
  
addEventHandler("onClientMarkerHit", jobMarker, 
function() 
--CODE HERE 
end 
) 

Where did you see that you need to unpack tables?

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