Hello everyone. I’m making a taxi job system and I’ve made a function where I need to save data inside a table.
I’m NOT really experienced with tables.
I need to save the stuff in the following order:
JobsAvailableCurrent{
[“JOB1”] = {“SpawnPoint”, “Destiny”, nil, 300},
}
Now, what my function should be doing is counting how many Rows are there, for example since there’s “JOB1”, the new job id will be: “JOB2”.
And I want to store it at the table.
My issue is that it gets replaced, and the JobID is still “JOB1”.
If you have any questions about my problem please ask me.
this is the part of my script:
JobsAvailableCurrent = {
--How it should be working:
--["JOB1"] = {"John St.", "Destiny Av.", 300, nil},
--["JOB2"] = {"Spawn1", "Cool St.", 300, nil}
}
function SpawnNPC(SpawnPoint, JobID, RandDestiny)
--Spawn NPC Function with those arguments
end
function GenerateCustomerNPC()
local RandomPickup = SpawnPoints1[math.random(1, #SpawnPoints1)]
if RandomPickup then
local DIRECTION = RandomPickup.Spawn_Direction.Value
local JobID = "JOB" .. tostring(#JobsAvailableCurrent + 1)
local RandomDestiny = Destinies1[math.random(1, #Destinies1)]
if RandomDestiny then
local Destiny_Dir = RandomDestiny.Destiny_Display.Value
if Destiny_Dir then
--Issue here:
JobsAvailableCurrent[JobID] = {DIRECTION, Destiny_Dir, nil, 300} --ISSUE HERE.
print("JOB ID FOR NEW NPC IS : "..JobID)
print("The table jobs are : "..#JobsAvailableCurrent)
print("TABLE: ")
for key, value in pairs(JobsAvailableCurrent) do
print(key, value[1], value[2], value[3], value[4])
end
end
end
end
end
My output looks like this:
As you can see, it’s not storing properly.
I’m NOT experienced with tables or dictionaries that much.
Thanks for your help