Certain factory object not spawning properly in windows build (SOLVED)

In my game I have a “bullet” object, and for some reason, in the windows build of the game (haven’t tested other builds), it doesn’t spawn properly. I can tell that part of the init() function has been run and that the object has been spawned, since it spawns something using a factory attached to the object, but something must be deleting it and not running the final() code, since it should be getting deleted.

I can’t tell if the issue is just bad code or if I’m accidentally using a debug feature without realising, because I don’t get this issue in the defold editor build

Here’s the game code
Shotgun Speed-Limit (Editor).zip (2.2 MB)

Here’s the bundled version
Shotgun Speed-Limit.zip (3.0 MB)

Could I get some help?

Only part of it? What if you add a print() at the end of the init() function (or even better set a breakpoint using the debugger).

How do you know this? Is it because you never see the object? If so, are you sure it doesn’t spawn behind something (ie it is in the same z-value as a background element or obstacle)?

Ah, sorry for the lack of clarity. In the bullet’s init function, it spawns 4 objects which are offset to it and parented to it, and then fills their sprite with a colour. In the bullet’s final function, it deletes these objects.

In the bundled version, It spawns the 4 objects, but does not parent them to the bullet or change their colour. It also does not delete them at any point in the program.

Hope that clears it up a little

Do you see any errors in the bundled Windows build? Launch it from a terminal.

BTW I tested an HTML5 build and got bombarded with errors in the browser console:

There is a (1/colour_of_pixel.r) that should be (1.0/colour_of_pixel.r).

1 Like

By looking at the bullet.script, you delete the items after .3 seconds.
Note that the init function is called before the enable, so it’s possible that the game objects are created, and while the game is loading, time has passed and it’s then time to remove them again.

-- init()  lifetime==0.3
	timer.delay(self.lifetime, false, function() -- After a given time
		if not self.hit then
			go.delete() -- Delete the object
1 Like

I was unaware that I could receive error messages in a build version, thanks for the heads up

also wow I did not test this thoroughly enough :grimacing:

1 Like

Will try something else here. Would having the timer be handled manually be viable? i.e. a self variable that only increments in the update function

Just tested this, it doesn’t seem to make any difference. At the very least it won’t be a problem for later. I’ll do some further testing

I finally managed to find where I had written this code, and it turns out that it was my only issue :sweat_smile:

Thanks for the help :smiley:


Scratch that, it wasn’t the main issue :pensive:

While it did solve my issue with the html and android builds not rendering properly, it appears that the game only seems to fire the bullets correctly in a debug build, so I’m not quite sure where my issue lies.

Again, I have a strong feeling that it’s me accidentally using a debug feature somewhere without realising it, but I could be completely wrong since I don’t know the difference between the debug and release versions. I’ll look into it further :+1:

Sounds weird. Are you depending on the result of a tostring on a hash value? This does not work in release builds.

1 Like

oohhh ok that clears things up haha

Is there any workaround to this? Is it just sending the id in a message? or are there other options?

Found the solution, turns out all I needed to do was use msg.url with the correct component name
Thanks for the help :).