Jump to content
noblebrad121

Having a small issue with a spawner

Recommended Posts

Hello i am trying to create a spawner just a simple one and it seems to have a small error i dont understand. Any help would be greatly appreciated.

 

 

here is my code

 

Script.spawnObject = "" --entity "spawn object"

Script.spawnTime= 1.0 --float "Spawn time"

self.timer = 0

 

function Script:UpdateWorld()

self.timer = self.timer + (Time:GetSpeed()/100)

if(self.timer > self.spawnTime) then

local newObject = self.spawnObject:Instance()

newObject:SetPosition(self.entity:GetPosition {)}

self.timer = 0

end

end

 

and the error i get says

 

script error

unexpected symbol near ')'

 

line 9

 

that is the only error that it has came up with.

 

thank you for any help

Share this post


Link to post

Well forst on line 3 is self not nil?

 

But your errors talking about line 9 where you accidentally used curly brackets.

 

newObject:SetPosition(self.entity:GetPosition())

Share this post


Link to post

well that fixed the line 9 but now the line 3 error came up it says

 

script error attempt to index global 'script' (a nil value)

line 3

 

i changed the script to this

 

Script.spawnObject = "" --entity "spawn object"

Script.spawnTime= 1.0 --float "Spawn time"

script.timer = nil

 

function Script:UpdateWorld()

self.timer = self.timer + (Time:GetSpeed()/100)

if(self.timer > self.spawnTime) then

local newObject = self.spawnObject:Instance()

newObject:SetPosition(self.entity:GetPosition ())

script.timer = 0

end

end

 

and it still did it after i changed the script.

 

btw i am really new to programming and stuff i dont really have any experience

Share this post


Link to post

Also, Script.timer should initially be set to 0 not nil or it will fail to add in the Script:UpdateWorld() function. Also, in the Script:UpdateWorld() function, using 'self.timer = 0' is the same as using 'Script.timer = 0' due to self = Script inside that function.

 

Suggest you go through the lua Tutorials located at the bottom of the tutorial page: http://www.leadwerks.com/werkspace/page/tutorials/

Share this post


Link to post

well its not spawning objects and for some odd reason the script:UpdateWorld() is not blue like it should be.

but function is blue.

 

 

Script.spawnObject = "" --entity "spawn object"

Script.spawnTime= 1.0 --float "Spawn time"

Script.timer = 0

 

function Script:UpdateWorld()

self.timer = self.timer + (Time:GetSpeed()/100)

if(self.timer > self.spawnTime) then

local newObject = self.spawnObject:Instance()

newObject:SetPosition(self.entity:GetPosition ())

self.timer = 0

end

end

 

thank you for mentioning that its good to know.

Share this post


Link to post

It works for me just fine. Did you drag an entity from the Scene panel into the Script's property panel?

post-14-0-42238000-1471804613.jpg

 

And the Script:UpdateWorld() is not blue.

Script.spawnObject = "" --entity "spawn object"

Script.spawnTime= 1.0 --float "Spawn time"

Script.timer = 0

 

function Script:UpdateWorld()

self.timer = self.timer + (Time:GetSpeed()/100)

if(self.timer > self.spawnTime) then

local newObject = self.spawnObject:Instance()

newObject:SetPosition(self.entity:GetPosition())

self.timer = 0

end

end

 

function Script:PostRender(context)

context:SetBlendMode(1)

context:DrawText("Timer: "..self.timer,2,142)

context:SetBlendMode(0)

end

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

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.

×
×
  • Create New...