Concatinated path does not work

Hi there,

i am new to Defold and lua. So a big Hello an a big Thank You for giving us your Engine for free and on top supporting us. Also hello and thank you to the all the other Devs around here for your support.

I have this piece of code:


	animal = "tiger"
	path = "/animals/" .. animal .. ".atlas"
	go.property("animalImage", resource.atlas(path))
	go.set("#animalSprite", "image", self.animalImage)

this ended up in the following errors:

ERROR:GAMEOBJECT: Properties can not be of type 'nil'.
ERROR:SCRIPT: animals/animals.script:9: the property 'image' of '#animalSprite' must be a number
stack traceback:
  [C]:-1: in function set
  animals/animals.script:9: in function <animals/animals.script:5>

what am i doing wrong? If i put the path directly in the resource.atlas("") all is fine. Also hash(path) produces the same error.

1 Like

So far from here:

It seems not be only the concatination. When you put a variable in the resource.atlas() instead of a string directly it did not get the string from the variable. Is there something i don’t understand right in lua or defold or is this a bug?

Welcome to Defold!

Your second post started to ring some bells for me. I think it might be related to this:

TL;DR: loading can not be done dynamically, Defold automatically scans for string paths when building/bundling.

I wonder if we could confirm this is the case by first doing a dummy load using a hardcoded string, and then do it again using a variable? If my theory is correct then that should work. You’ll need to redesign if so, but at least you’ll know “why”.

2 Likes

Ah, i see. Thank you a lot, that helped me out. Then i will rewrite some stuff here.