Pass url as a property?

Sorry, I’ve spent an hour checking forums and I know that I can’t use string variable (path to texture) as a property, but I can use url. I just can’t pass it to property.

One of a dozen tries. This one gives “go.set failed with error code -10”

local path = "/data/".. type.. "/" .. number .. ".jpg"
go.property("texture", resource.texture())
go.property("texture", msg.url(path))

All my other tries end up with GO does not have any property called ‘texture’.

This works:

go.property("my_texture", resource.texture("/gooey/themes/dirtylarry/images/button_normal.png"))
2 Likes

Sure, but I have a folder of backgrounds and I need only one of them that goes by a number. I.e. url is a variable (string).

You can set a dynamically generated value, although not when declaring the go.property(). This works:

local state = "pressed"
go.set("#", "my_texture", hash("/gooey/themes/dirtylarry/images/button_" .. state .. ".png"))
2 Likes

go.set failed with error code -10

go.property("texture", resource.texture())
go.set("#", "texture", hash ("/data/".. locType .. "/" .. roomv .. ".jpg"))
go.set("/floor#floor", "texture0", go.get("#script", "texture"))

=(

This should be outside the lifecycle functions (init, final, update etc)

This should be inside the lifecycle functions.

Yes. It gives error “go.set failed with error code -10” in last line.

I mean the cause of an error is in
go.set("#", “mytexture”, hash ("/data/"… type … “/” … number … “.jpg”))

setting path in go.property(“mytexture”, resource.texture("/…")) works.

Just to correct my previous feedback…

go.property("texture", resource.texture("/data/folder/file.jpg"))
go.set("#model", "texture0", go.get("#", "texture"))

Works!

go.property("texture", resource.texture("/data/folder/file.jpg"))
go.set("#", "texture", hash ("/data/" .. "folder/" .. "file.jpg"))
go.set("#model", "texture0", go.get("#", "texture"))

Returns go.set failed with error code -10

Hmm, ok. -1 = PROPERTY_RESULT_RESOURCE_NOT_FOUND

I’ll experiment a bit to figure this out. But it makes sense that you get a “resource not found” error if you change texture using code and specify a dynamic resource hash like hash("/foo" .. count .. ".jpg"). The build pipeline will not know which foo*.jpg to include. We still need to know about all resource up front to be able to include them in the application bundle.

1 Like

Oh, got your point. Just made another property “texture2” to “store” correct path there. It transformed my hash: [/data/cres/e1.jpeg] to hash: [/data/cres/e1.texturec] and dynamic texture change worked after that.

Should I somehow parse all my images to that format? I have about 200 images there. =)

UPD:

	go.property("texture", resource.texture("/data/cres/01.jpg"))
	go.property("texture", resource.texture("/data/cres/e1.jpg"))

Gives the same error. Looks like it can handle “jpg” only when unique property is being initiated.
And looks like it doesn’t matter if I create texture property inside local function.

Maybe I should also ask what it is you want to do? :slight_smile: You have many images/textures, and you wish to, at run-time, select one to use on a model? Is that correct?

What about something like this:

go.property("t1", resource.texture("/data/cres/01.jpg"))
go.property("t2", resource.texture("/data/cres/02.jpg"))
go.property("t3", resource.texture("/data/cres/03.jpg"))
go.property("t200", resource.texture("/data/cres/200.jpg"))

function init(self)
	local t = go.get("#", "t" .. tostring(3))
	go.set("#model", "texture0", t)
end

You should probably create a bash script or something to generate a script file containing all of the go.property() entries though. Or maybe an editor extension script could do it for you.

1 Like

Thanks! I’ll try to find info on that editor extension scripts.

britzl, maybe that -10 error is a bug and it can be fixed? Since writing down 20% of image files in the game is a total mess.

Just tried external lib “Lerg/extension-imageloader”.
Same go.get failed with error code -10

If a file isn’t directly referenced in a resource (atlas, tilesource, model, spine etc) or if the resource isn’t used it will not get included in the final build. This is by design. You as a developer should not have to worry about your app containing unused files. Everything in the final bundle is referenced by some component and could therefore at some point be used by your code.

You can use Bundle and Custom Resources to include arbitrary files that you can load at runtime. But I’m not sure if you can load one of those and use it as a model texture.

Yes it’s in Custom Resources. But I’ve just found a solution =) I’ll add those textures to object atlases and replace models with simpler sprites. It’s even better then the original concept.

Thank you for your help britzl!

1 Like