Jump to content

access lua table in Script:Start()


tipforeveryone
 Share

Recommended Posts

My goal is place some boxes at the position of some pre-placed pivots

I have 3 pivots (pivot1, pivot2, pivot3)

Scripts 1: which is attached to pivot1 and 2

function Script:Start()
  	table.insert(global_table,self.entity)
end

(global_table was declared in main.lua, before the while loop)

Script 2: which is attached to pivot3

function Script:Start()
    for key,value in ipairs(global_table) do
    	local box = Model:Box()
    	box:SetPosition(value:GetPosition(true))
    end
end

Script 2 does not work, because there is nothing inside the global_table to execute, all Script:Start() function are started at the same time.

How can I force the Start() function of script2 (attached to pivot3) to be executed after all others execution?

Link to comment
Share on other sites

5 hours ago, tipforeveryone said:

Script 2 does not work, because there is nothing inside the global_table to execute, all Script:Start() function are started at the same time.

How can I force the Start() function of script2 (attached to pivot3) to be executed after all others execution?

There is no build in way to force the pivot3 scripts from being exucted first. What you can do is wait a couple of frames before calling the for loop in your pivot 3 script.

  • Thanks 1
Link to comment
Share on other sites

"My goal is place some boxes at the position of some pre-placed pivots"

 

You stated a goal but I wonder if this is the entire goal really? Why do you want to great a global variable to store these in? To reach your goal just make a Box script and attach it to the pivots and inside it's Start() it makes a box at self.entity position. That would reach your goal.

Link to comment
Share on other sites

Yeah it is not actually my goal, I want to place my character spawn position by using pivots. I place pivots in editor and when I run the game, my characters will be placed with pivots's position.

Anyway, I found the solution, I put Script2 into UpdateWorld(), not in Start(), with a variable which can help execute character create code only one time. :D

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...