Jump to content

Can't take values from an array


Roderen

Recommended Posts

Posted
local veh = {"411, 2505.1791992188, -1664.51953125, 13.391730308533, 0, 0, 90"}

function Vehicles()
    createVehicle(veh)
end
addEventHandler("onResourceStart", root, Vehicles)

 

  • Moderators
Posted
53 minutes ago, Roderen said:
local veh = {"411, 2505.1791992188, -1664.51953125, 13.391730308533, 0, 0, 90"}

Do not use "", they are making the inner content a string. A string is a character set, which is not very handy for spawn dimensions.

local veh = {411, 2505.1791992188, -1664.51953125, 13.391730308533, 0, 0, 90}

 

Try this:

local veh = {411, 2505.1791992188, -1664.51953125, 13.391730308533, 0, 0, 90}



function Vehicles()
    createVehicle(unpack(veh))
end
addEventHandler("onResourceStart", root, Vehicles)

 

Posted
8 minutes ago, IIYAMA said:

Do not use "", they are making the inner content a string. A string is a character set, which is not very handy for spawn dimensions.

local veh = {411, 2505.1791992188, -1664.51953125, 13.391730308533, 0, 0, 90}

 

Try this:

local veh = {411, 2505.1791992188, -1664.51953125, 13.391730308533, 0, 0, 90}



function Vehicles()
    createVehicle(unpack(veh))
end
addEventHandler("onResourceStart", root, Vehicles)

 

Thank you! And the last question. How to add several values to an array at once (in my case, these are coordinates)?
There are two coordinates. How to correctly enter more than one value into an array?
1 - 2501.7138671875, -1658.6333007812, 13.387635231018 ,-0, 0, 140.31568908691
2 - 411, 2505.1791992188, -1664.51953125, 13.391730308533, 0, 0, 90

  • Like 1
  • Moderators
Posted
1 hour ago, Roderen said:

There are two coordinates. How to correctly enter more than one value into an array?

 

You can place a tables in tables. (Note: Not literally as under the hood only a reference to the sub tables will be saved in the outer table. But that is another story...)

local veh = { -- < outer table
	{411, 2505.1791992188, -1664.51953125, 13.391730308533, 0, 0, 90}, -- < inner tables separated by ,
	{411, 2505.1791992188, -1664.51953125, 13.391730308533, 0, 0, 90}
}

 

And using a loop to process them all:

function Vehicles()
	for i=1, #veh do
		createVehicle(unpack(veh[i]))
	end
end
addEventHandler("onResourceStart", root, Vehicles)

 

  • Thanks 1

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