# \[SOLVED\] How to create a queue of spawning game objects after one another and stopping based on a countdown timer

**URL:** <https://forum.defold.com/t/solved-how-to-create-a-queue-of-spawning-game-objects-after-one-another-and-stopping-based-on-a-countdown-timer/71977>\
**Category:** Questions\
**Created:** [October 31, 2022, 3:53am UTC](https://forum.defold.com/t/solved-how-to-create-a-queue-of-spawning-game-objects-after-one-another-and-stopping-based-on-a-countdown-timer/71977 "2022-10-31T03:53:39Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![accoladious](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/accoladious/32/30113_2.png) [@accoladious](https://forum.defold.com/u/accoladious)\
**Post date:** [October 31, 2022, 3:53am UTC](https://forum.defold.com/t/solved-how-to-create-a-queue-of-spawning-game-objects-after-one-another-and-stopping-based-on-a-countdown-timer/71977/1 "2022-10-31T03:53:39Z")

</div>

I’m trying to spawn objects in a queue. Like I do something, that’ll get rid of the object, then there’ll be a next instance of that object, over and over. In the background there’ll be a timer, when that timer ends, the game will stop and return back to the main collection. The object instances don’t need to be stored as data before runtime, there doesn’t need to be any data stored about they’re destroyed.

Currently, I have a collection that contains a factory that’s intended to spawn a game object ( inside I have a temp mesh, sound component, and a script that holds its properties and functions). I also have a script inside of that collection under a separate game object and am also using Ludobits and the timer script.

I’m not sure how you would create a queue though nor how to use the timer properly.

```lua
local countdown = require "ludobits.m.timer"

local function create_object()
	-- create object by way of factory.create
end

local function delete_object()
	-- delete object
	-- call create_object() again, but what about the timer?
end

function init(self)
	-- Once countdown is done, return to main collection, however am not using .once correctly
	--- Create a timer that will call a function after a certain time
	-- has elapsed.
	-- @param seconds The number of seconds before the callback should be invoked
	-- @param callback The function to invoke when the time has elapsed
	-- @return The timer instance
	countdown.once(8, msg.post("main:/main", "game_over"))
end

function on_message(self, message_id, message, sender)
	if message_id == hash("start_minigame") then
		-- start the minigame from this script
	end
end

```

---

<div class="post-metadata">

**Author:** ![britzl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/britzl/32/23_2.png) [@britzl](https://forum.defold.com/u/britzl)\
**Post date:** [October 31, 2022, 7:12am UTC](https://forum.defold.com/t/solved-how-to-create-a-queue-of-spawning-game-objects-after-one-another-and-stopping-based-on-a-countdown-timer/71977/2 "2022-10-31T07:12:28Z")

</div>

> [@accoladious](#):
>
> `local countdown = require "ludobits.m.timer"`

Oh, this is probably a very old version of Ludobits. The latest version has no timer/countdown module. There is no need for it since Defold has a built in timer nowadays. Here’s how I’d do it:

```lua
-- minigame.script

local function delete_object(self)
	if self.current then
		go.delete(self.current)
		self.current = nil
	end
end

local function create_object(self)
	-- make sure there is no object
	delete_object(self)
	self.current = factory.create("#factory")
end

function on_input(self, action_id, action)
	-- spawn a new item on each click/touch
	if action_id == hash("touch") and action.pressed then
		msg.post("/spawner", "spawn")
	end
end

function on_message(self, message_id, message, sender)
	if message_id == hash("start_minigame") then
		msg.post(".", "acquire_input_focus")
		create_object(self)
		timer.delay(8, false, function()
			msg.post("main:/main", "game_over")
		end)
	end
end

```

---

<div class="post-metadata">

**Author:** ![accoladious](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/accoladious/32/30113_2.png) [@accoladious](https://forum.defold.com/u/accoladious)\
**Post date:** [October 31, 2022, 2:33pm UTC](https://forum.defold.com/t/solved-how-to-create-a-queue-of-spawning-game-objects-after-one-another-and-stopping-based-on-a-countdown-timer/71977/3 "2022-10-31T14:33:32Z")

</div>

Ah I see, thank you, I was looking at an example, the Mini Mega Games, I think that’s what it’s called, because I was also trying to do something Warioware-esque. Thanks Britzl. Speaking of that, would flow from ludobits be necessary? From what I understand it’s basically, do this then do this, like a sequence.

Mini Mega Party, oops.

---

<div class="post-metadata">

**Author:** ![britzl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/britzl/32/23_2.png) [@britzl](https://forum.defold.com/u/britzl)\
**Post date:** [October 31, 2022, 2:59pm UTC](https://forum.defold.com/t/solved-how-to-create-a-queue-of-spawning-game-objects-after-one-another-and-stopping-based-on-a-countdown-timer/71977/4 "2022-10-31T14:59:04Z")

</div>

> [@accoladious](#):
>
> Speaking of that, would flow from ludobits be necessary? From what I understand it’s basically, do this then do this, like a sequence

Yeah, the flow module can help when you need to run several asynchronous things one after the other. It is useful sometimes, other times it only complicates things.

---

<div class="post-metadata">

**Author:** ![accoladious](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/accoladious/32/30113_2.png) [@accoladious](https://forum.defold.com/u/accoladious)\
**Post date:** [November 1, 2022, 4:35pm UTC](https://forum.defold.com/t/solved-how-to-create-a-queue-of-spawning-game-objects-after-one-another-and-stopping-based-on-a-countdown-timer/71977/5 "2022-11-01T16:35:00Z")

</div>

```lua
local function create_book(self)
	-- attempt to call global 'delete_book' (a nil value)
	delete_book(self)
	self.book_id = factory.create("#random-book-factory", vmath.vector3(-1.0, 0, 0))
	
	go.set(self.book_id, "position.x", 0.0)
	go.animate(self.book_id, "position.x", go.PLAYBACK_ONCE_FORWARD, 100, go.EASING_INQUART, 2)
	sound.play(self.book_id.."#sliding-sound")
end

local function delete_book(self)
	if self.book_id then
		go.set(self.book_id, "position.x", -1.0)
		go.animate(self.book_id, "position.x", go.PLAYBACK_ONCE_FORWARD, 100, go.EASING_INQUART, 2)
		sound.play(self.book_id.."#sliding-sound")
		go.delete(self.book_id)
		self.book_id = nil
	end
end

```

So I’m getting an error `-- attempt to call global 'delete_book' (a nil value)`, but I don’t think that should be happening since there’s the if statement, so I’m confused?

---

<div class="post-metadata">

**Author:** ![selimanac](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/selimanac/32/6397_2.png) [@selimanac](https://forum.defold.com/u/selimanac)\
**Post date:** [November 1, 2022, 5:11pm UTC](https://forum.defold.com/t/solved-how-to-create-a-queue-of-spawning-game-objects-after-one-another-and-stopping-based-on-a-countdown-timer/71977/6 "2022-11-01T17:11:04Z")

</div>

Lua runs top-\>down. Move delete\_book function before the create\_book

---

<div class="post-metadata">

**Author:** ![accoladious](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/accoladious/32/30113_2.png) [@accoladious](https://forum.defold.com/u/accoladious)\
**Post date:** [November 1, 2022, 5:43pm UTC](https://forum.defold.com/t/solved-how-to-create-a-queue-of-spawning-game-objects-after-one-another-and-stopping-based-on-a-countdown-timer/71977/7 "2022-11-01T17:43:18Z")

</div>

Oh I see, thank you, I didn’t realise that.

---

<div class="post-metadata">

**Author:** ![accoladious](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/accoladious/32/30113_2.png) [@accoladious](https://forum.defold.com/u/accoladious)\
**Post date:** [November 1, 2022, 6:09pm UTC](https://forum.defold.com/t/solved-how-to-create-a-queue-of-spawning-game-objects-after-one-another-and-stopping-based-on-a-countdown-timer/71977/8 "2022-11-01T18:09:42Z")

</div>

```lua
ERROR:GAMEOBJECT: Could not initialize when spawning /minigames/inventory/book/book.goc.
ERROR:GAMEOBJECT: Could not spawn an instance of prototype /minigames/inventory/book/book.goc.
ERROR:SCRIPT: ...games/inventory/insert-book-code/insert-book-code.script:16: 'nil' does not have any property called 'position.x'
stack traceback:

```

I put the delete\_book function before the create\_book function.

 ![book.go](https://forum-defold-uploads.b-cdn.net/original/3X/4/3/43ace944eaf8c87a5f1018c812cb2925f398a348.png)  
This is the game object, so I’m confused as to why it’s not able to spawn an instance of it.

---

<div class="post-metadata">

**Author:** ![selimanac](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/selimanac/32/6397_2.png) [@selimanac](https://forum.defold.com/u/selimanac)\
**Post date:** [November 1, 2022, 6:25pm UTC](https://forum.defold.com/t/solved-how-to-create-a-queue-of-spawning-game-objects-after-one-another-and-stopping-based-on-a-countdown-timer/71977/9 "2022-11-01T18:25:52Z")

</div>

It is hard to say. But I guess your previous code is from /minigames/inventory/book/book.script file which is in the Gameobject. If so, you are trying to remove Gameobject, inside the Gameobject and trying to spawn a new one from already deleted script file. Very confusing 😃

This logic is not correct. You need to have a central script which spawns and deletes gameobjects.

Like this:

> **[Spawn game object](https://defold.com/examples/factory/basic/)**
>
> This example shows how to dynamically spawn game objects with a factory component.

---

<div class="post-metadata">

**Author:** ![accoladious](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/accoladious/32/30113_2.png) [@accoladious](https://forum.defold.com/u/accoladious)\
**Post date:** [November 1, 2022, 6:44pm UTC](https://forum.defold.com/t/solved-how-to-create-a-queue-of-spawning-game-objects-after-one-another-and-stopping-based-on-a-countdown-timer/71977/10 "2022-11-01T18:44:57Z")

</div>

Ah I see, I was reading the link you sent me, I did make a script though that’s supposed to call the factory.

 ![image](https://forum-defold-uploads.b-cdn.net/original/3X/e/b/ebf58d0c1892bbc869b36b556fe63e7762dc759d.png)  
insert-book-code is what’s housing the code I sent you, not the book.script. Unless I’m misunderstanding how that works.

---

<div class="post-metadata">

**Author:** ![selimanac](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/selimanac/32/6397_2.png) [@selimanac](https://forum.defold.com/u/selimanac)\
**Post date:** [November 1, 2022, 7:00pm UTC](https://forum.defold.com/t/solved-how-to-create-a-queue-of-spawning-game-objects-after-one-another-and-stopping-based-on-a-countdown-timer/71977/11 "2022-11-01T19:00:22Z")

</div>

Again, it is not easy for us to answer this question without seen all the code(I don’t know what is on line x). But error is caused by (probably) `self.book_id` is “nil” which you can’t set it is position.x. It is better to use `pprint()` and `print()` to figure out the problem. If it is nil before you are setting its position then you are doing something wrong by setting `self.book_id = nil` on somewhere.

---

<div class="post-metadata">

**Author:** ![accoladious](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/accoladious/32/30113_2.png) [@accoladious](https://forum.defold.com/u/accoladious)\
**Post date:** [November 1, 2022, 7:28pm UTC](https://forum.defold.com/t/solved-how-to-create-a-queue-of-spawning-game-objects-after-one-another-and-stopping-based-on-a-countdown-timer/71977/12 "2022-11-01T19:28:59Z")

</div>

No problem, that’s my bad, I’ll just post all of what I have.

 ![collection that's being started at runtime](https://forum-defold-uploads.b-cdn.net/original/3X/5/3/537504ffc9a5b416149c75f508ef93ae5d128a92.png)  
 ![image](https://forum-defold-uploads.b-cdn.net/original/3X/d/5/d522413566a134e303281c20e2752b2882654eaf.png)

 ![image](https://forum-defold-uploads.b-cdn.net/original/3X/8/f/8fd304aa07392ea60096f74ac2247b0b01d526f3.png)  
`book.script` of `book.go`

```lua
function init(self)
	generate_book_appearance()
	generate_book_code()
end

local function generate_book_code()
	self.book_code = ""
	local charset = {} do
		-- Ký tự [0-9a-zA-Z] dưới dạng mã ASCII: https://www.rapidtables.com/code/text/ascii-table.html
		for c = 48, 57 do table.insert(charset, string.char(c)) end
		for c = 65, 90 do table.insert(charset, string.char(c)) end
		for c = 97, 122 do table.insert(charset, string.char(c)) end
	end
	-- [0-9a-zA-Z]{4}-[0-9a-zA-Z]{4}-[0-9a-zA-Z]{4}-[0-9a-zA-Z]{4}
	while (string.len(self.book_code) <= 19) do 
		if (#self.book_code % 5 == 0) then
			self.book_code = self.book_code .."-" 
		else
			self.book_code = self.book_code .. charset[math.random(1, #charset)] 
		end
	end
	label.set_text("#random_book_code_label", self.book_code)
	msg.post("/computer#computer", "actual_book_code", self.book_code)
end

local function generate_book_appearance()
	go.set("#random-book-model", "tint", vmath.vector4(1,0,0,1))
end

```

which is being spawned via `random_book_factory` from `insert-book-code.script`.

```lua
local function delete_book(self)
	if self.book_id then
		go.set(self.book_id, "position.x", -1.0)
		go.animate(self.book_id, "position.x", go.PLAYBACK_ONCE_FORWARD, 100, go.EASING_INQUART, 2)
		sound.play(self.book_id.."#sliding-sound")
		go.delete(self.book_id)
		self.book_id = nil
	end
end

local function create_book(self)
	-- attempt to call global 'delete_book' (a nil value)
	delete_book(self)
	self.book_id = factory.create("#random_book_factory", vmath.vector3(-1.0, 0, 0))
	
	go.set(self.book_id, "position.x", 0.0)
	go.animate(self.book_id, "position.x", go.PLAYBACK_ONCE_FORWARD, 100, go.EASING_INQUART, 2)
	sound.play(self.book_id.."#sliding-sound")
end

function init(self)
	msg.post("/computer#computer", "acquire_input_focus")
	create_book(self)
	timer.delay(8, false, function()
		msg.post("main:/main", "game_over")
	end)
end

function on_message(self, message_id, message, sender)
        -- still trying to figure how to delete book then respawn it again after the code's accepted
	if message_id == hash("delete_book") then
		delete_book()
	end
end

```

then inside another game object in the same collection, `computer.go`, I have a script called `computer.script`. Basically I’m trying to make a ‘check in’ system. A random book spawns, the player types in the computer and has to match the code on it, then if it matches, it destroys the book and the book gets created again until the timer runs out and the collection unloads.

```lua
local actual_book_code = ""

function init(self)
	self.message = ""
end

function on_input(self, action_id, action)
	if action_id == hash("type") then
		msg.post("/computer_sound#computer-sound", "play_keyboard")
		self.message = self.message .. action.text
		label.set_text("#code_input_box", self.message)
	elseif action_id == hash("backspace") and action.repeated then
		msg.post("/computer_sound#computer-sound", "play_keyboard")
		local l = string.len(self.message)
		self.message = string.sub(self.message, 0, l-1) 
		label.set_text("#code_input_box", self.message) 
	elseif action_id==hash("enter") then
		msg.post("/computer_sound#computer-sound", "play_keyboard")
		if self.message == actual_book_code then
			msg.post("/minigame_go#insert-book_code", "delete_book")
		end
	end
end

function on_message(self, message_id, message, sender)
	if message_id == hash("actual_book_code") then
		actual_book_code = message.book_code 
	end
end

```

I was reading [Game object API documentation at go.animate](https://defold.com/ref/go/#go.animate:url-property-playback-to-easing-duration-%5Bdelay%5D-%5Bcomplete_function%5D) and seeing `property: id of the property to animate`so I thought I could pass in the position, and I remember seeing an example too. I’m probably making a lot of errors in the code and am trying to figure out how to decouple.

---

<div class="post-metadata">

**Author:** ![selimanac](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/selimanac/32/6397_2.png) [@selimanac](https://forum.defold.com/u/selimanac)\
**Post date:** [November 1, 2022, 7:34pm UTC](https://forum.defold.com/t/solved-how-to-create-a-queue-of-spawning-game-objects-after-one-another-and-stopping-based-on-a-countdown-timer/71977/13 "2022-11-01T19:34:58Z")

</div>

> [@accoladious](#):
>
> I was reading [Game object API documentation at go.animate](https://defold.com/ref/go/#go.animate:url-property-playback-to-easing-duration-%5Bdelay%5D-%5Bcomplete_function%5D) and seeing `property: id of the property to animate`so I thought I could pass in the position, and I remember seeing an example too.

This is correct.

> [@accoladious](#):
>
> I’m probably making a lot of errors in the code and am trying to figure out how to decouple.

At least by using pprint() and print() functions. Lets try to find the problem by using these functions.

---

<div class="post-metadata">

**Author:** ![selimanac](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/selimanac/32/6397_2.png) [@selimanac](https://forum.defold.com/u/selimanac)\
**Post date:** [November 1, 2022, 7:47pm UTC](https://forum.defold.com/t/solved-how-to-create-a-queue-of-spawning-game-objects-after-one-another-and-stopping-based-on-a-countdown-timer/71977/14 "2022-11-01T19:47:13Z")

</div>

Remember this and check out `book.script` of `book.go`:

> [@selimanac](#):
>
> Lua runs top-\>down.

---

<div class="post-metadata">

**Author:** ![accoladious](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/accoladious/32/30113_2.png) [@accoladious](https://forum.defold.com/u/accoladious)\
**Post date:** [November 2, 2022, 12:23am UTC](https://forum.defold.com/t/solved-how-to-create-a-queue-of-spawning-game-objects-after-one-another-and-stopping-based-on-a-countdown-timer/71977/15 "2022-11-02T00:23:46Z")

</div>

> [@selimanac](#):
>
> Lua runs top-\>down.

I see, I’m still slightly a bit confused by this. So does that mean that it doesn’t matter when `on_message` is called? What I’m understanding when you say lua is top down is that it means the functions get built in order and has to be called from the top down? Should I be making `self.book_id` somewhere else.

  
I ended up debugging it, the typing works, the sound for it works. You seem to be right though, it’s got to do with the `book.script` so I tried reordering the `init` to be last. Wait, shouldn’t `generate_book_code` be run first, before even creating the book? Wait that doesn’t make sense. When you create the book, you’re running the initialising method.

---

<div class="post-metadata">

**Author:** ![ross.grams](https://forum-defold.b-cdn.net/letter_avatar_proxy/v4/letter/r/cab0a1/32.png) [@ross.grams](https://forum.defold.com/u/ross.grams)\
**Post date:** [November 2, 2022, 12:49am UTC](https://forum.defold.com/t/solved-how-to-create-a-queue-of-spawning-game-objects-after-one-another-and-stopping-based-on-a-countdown-timer/71977/16 "2022-11-02T00:49:38Z")

</div>

The issue you’re having right now is not because of ordering, you already fixed that. You need to fix the errors you’re getting in the console. Nothing will work if your script crashes. Start from the very first one and fix what it tells you is wrong.

> `book.script:7: attempt to index global 'self' (a nil value)`

---

<div class="post-metadata">

**Author:** ![accoladious](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/accoladious/32/30113_2.png) [@accoladious](https://forum.defold.com/u/accoladious)\
**Post date:** [November 2, 2022, 12:55am UTC](https://forum.defold.com/t/solved-how-to-create-a-queue-of-spawning-game-objects-after-one-another-and-stopping-based-on-a-countdown-timer/71977/17 "2022-11-02T00:55:20Z")

</div>

I see, thank you. About that error though, if the problem is that `self.book_code = ""` is nil, then I’m either thinking that my goal is to make it either a local variable or to reorder when I create that variable. With local variables, can you pass them through `msg.post`? I’m slightly confused on how to use it. I was thinking of passing it to my `computer.script`  
 ![image](https://defold-forum-bucket.nbg1.your-objectstorage.com/original/3X/0/d/0d088739d34d5bd930d214448e4bb9cea450d3e5.png)  
but I don’t know if message call the book\_code variable? I did read the documentation, I’m just confused about the message parameter. Yea no, reordering it wouldn’t work I think, I also just tried that.

---

<div class="post-metadata">

**Author:** ![ross.grams](https://forum-defold.b-cdn.net/letter_avatar_proxy/v4/letter/r/cab0a1/32.png) [@ross.grams](https://forum.defold.com/u/ross.grams)\
**Post date:** [November 2, 2022, 1:06am UTC](https://forum.defold.com/t/solved-how-to-create-a-queue-of-spawning-game-objects-after-one-another-and-stopping-based-on-a-countdown-timer/71977/18 "2022-11-02T01:06:22Z")

</div>

No no, back up. Read the error message more carefully.

> `attempt to index`

Attempting to _index_ something means you’re trying to use it as a table and access a value inside it using a key.

> `attempt to index global`

This means that the error is happening when your script attempts to access a _global_ variable.

> `attempt to index global 'self'`

The global variable that you’re trying to use is named: ‘self’.

> `'self' (a nil value)`

The value of the global variable that you were trying to use is nil.  
Since you were trying to get a value from the variable using a key, the variable was expected to be a table. Instead of a table, it was nil, hence the error.

[Edit]: Looking for a **global** variable means that no **local** variable was found with that name, in the current scope.

---

<div class="post-metadata">

**Author:** ![accoladious](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/accoladious/32/30113_2.png) [@accoladious](https://forum.defold.com/u/accoladious)\
**Post date:** [November 2, 2022, 1:34am UTC](https://forum.defold.com/t/solved-how-to-create-a-queue-of-spawning-game-objects-after-one-another-and-stopping-based-on-a-countdown-timer/71977/19 "2022-11-02T01:34:18Z")

</div>

I see. Oh I see, I’m reading your previous [post on Explanation of the “self” argument for dummies](https://forum.defold.com/t/explanation-of-the-self-argument-for-dummies/44691/2) and I think I’m somewhat understanding it. I originally used `self` to make it so the variable be different for every instance so I think I’m doing it right.So line 7 is `self.book_code = ""`. So I’m debugging it again, reaching to the original error, clicking the triangle to forward it and jumping to here.

![image](https://defold-forum-bucket.nbg1.your-objectstorage.com/original/3X/7/3/73e74389e50a4d1208e78169c7301b8288409053.png)

So if `self` is a table, and I’m indexing a global `self` from my `book.script`, then does that mean I was trying to access the `self` table inside of `insert-book-code.script` or vice versa?  
Sorry, I’m just having a hard time grasping this.

I guess another question would be, what is the key in this case.

Wait, so I’m using the factory to create an instance of a game object, and I’m using `self` to make sure each variable of each instance of it is unique and not shared, but then inside of that game object, I have a script that’s also attempting to use `self` to make sure each instance of it has unique variable values. 🤔

Wait a minute, if I’m already making a new instance of `book.go` inside of `insert-book-code.script`, why would I need `self.book_code` inside of `book.script`.

---

<div class="post-metadata">

**Author:** ![ross.grams](https://forum-defold.b-cdn.net/letter_avatar_proxy/v4/letter/r/cab0a1/32.png) [@ross.grams](https://forum.defold.com/u/ross.grams)\
**Post date:** [November 2, 2022, 1:42am UTC](https://forum.defold.com/t/solved-how-to-create-a-queue-of-spawning-game-objects-after-one-another-and-stopping-based-on-a-countdown-timer/71977/20 "2022-11-02T01:42:20Z")

</div>

Line 7 from the error is:

```lua
self.book_code = ""

```

So the key in this case is: `"book_code"`, since

```lua
self.book_code

```

is just shorthand for:

```lua
self["book_code"]

```

The one and only problem is: no local variable named ‘`self`’ exists in the context where you expected it to. Just take a look at these few lines:

```lua
function init(self)
	generate_book_appearance()
	generate_book_code()
end

local function generate_book_code()
	self.book_code = ""

```

Where’s self?

[Next page](https://forum.defold.com/t/solved-how-to-create-a-queue-of-spawning-game-objects-after-one-another-and-stopping-based-on-a-countdown-timer/71977.md?page=2)
