Issues with endless runner segments

I`m making and Endless Runner

I want to have segments

Sample segment is:

go.property(“speed”, 2000)

local segments = {}

function init(self)

local position = vmath.vector3(640,360,0)

local segmentUrl = collectionfactory.create(“segment1#collectionfactory”, position , vmath.quat(), {}, 1)

table.insert(segments, segmentUrl)

–msg.post(segmentUrl[hash(“/main”)], “SetSpeed”, { speed = self.speed })

end

function update(self, dt)

local speedDifference = dt * self.speed

local segmentUrl = nil

local firstSegment = segments[1]

local firstSegmentPosition = go.get_position(segments[1][hash(“/main”)])

if firstSegmentPosition.x < -3200 then

##l’ocal ids = segments[1]

go.delete_all(ids)

table.remove(segments, 1)

end

end

the above script gives this error:
WARNING:GAMEOBJECT: go.delete_all(): instance could not be resolved

Any ideas?

l’ocal ids = segments[1] - is that normal? (no)

Search your code for syntax errors, this may cause problems sometimes :smiley:

I also tried this

if firstSegmentPosition.x < -3200 then
	go.delete_all(segments[1])
	table.remove(segments, 1)
end

result was the same

WARNING:GAMEOBJECT: go.delete_all(): instance could not be resolved
WARNING:GAMEOBJECT: go.delete_all(): instance could not be resolved
WARNING:GAMEOBJECT: go.delete_all(): instance could not be resolved
WARNING:GAMEOBJECT: go.delete_all(): instance could not be resolved
WARNING:GAMEOBJECT: go.delete_all(): instance could not be resolved
DEBUG:SCRIPT: deleting segment

Sorry, maybe I’m not pro in Lua, but have you solved that syntax error? If yes, then we probably should wait for the master

the syntax thing was during text formatting.in the post

Okay :smiley: You know, I’ve been making games in Unity (writing in C#), and after trying Lua today, googling for manual on official website, I concluded, that C# is a lot easier :slight_smile:

OK, so apparently the issue is connected to the fact that:
I have collectible elements that are deleted when the character touches them

Since they are spawned with the connection then when I delete the collection and those elements are already deleted, it throws the warning

Any idea how to delete element from collection when its deleted?

You get a list of all spawned game objects from collectionfactory.create(). Any objects you delete before calling go.delete_all() should be removed from that list. One way to do it is to have each game object send a message back to the spawner script when it is deleted so the spawner script can manage the bookkeeping.

2 Likes