[0.16.36] Sprite Path from file not working

This subforum contains all the issues which we already resolved.
Post Reply
blueblue
Long Handed Inserter
Long Handed Inserter
Posts: 75
Joined: Tue Apr 11, 2017 7:39 pm
Contact:

[0.16.36] Sprite Path from file not working

Post by blueblue »

According to the documentation on sprite paths it is possible to load sprite files from base. I cannot get this to work in sprite buttons. As a minimal example, the following two commands create a button, however it is invisible although the file exists in the base mod.

Code: Select all

/c game.player.gui.top.add{type="sprite", sprite="file/__base__/graphics/icons/alien-artifact-goo.png", name="button"}
/c game.player.gui.top.add{type="sprite", sprite="file/graphics/icons/alien-artifact-goo.png", name="button2"}
unique_2 on discord and mod portal

sparr
Smart Inserter
Smart Inserter
Posts: 1327
Joined: Fri Feb 14, 2014 5:52 pm
Contact:

Re: [0.16.36] Sprite Path from file not working

Post by sparr »

First, "sprite" is not the element type you want for a button. You want a "sprite-button".

Second... I have no idea why that sprite path doesn't work.

Code: Select all

/c game.player.gui.top.add{type="sprite-button", sprite="file/__base__/graphics/icons/alien-artifact-goo.png", name="button"} 
This creates a visible button... with no sprite. I'm stumped there.

osldgoth
Long Handed Inserter
Long Handed Inserter
Posts: 93
Joined: Thu Feb 26, 2015 3:52 am
Contact:

Re: [0.16.36] Sprite Path from file not working

Post by osldgoth »

I too have been trying to use file for a sprite path. I've tried validating the path with gui.is_valid_sprite_path() which returns true for the sprite I try to use but the button is empty. however I am not convinced is_valid_sprite_path() works right.

I am trying to use "__core__/graphics/questionmark"

FALSE --as expected

Code: Select all

/c game.print(game.player.gui.is_valid_sprite_path("file"))
TRUE --not sure why, but ok.

Code: Select all

/c game.print(game.player.gui.is_valid_sprite_path("file/"))
TRUE --as expected

Code: Select all

/c game.print(game.player.gui.is_valid_sprite_path("file/__core__"))
TRUE --expected false

Code: Select all

/c game.print(game.player.gui.is_valid_sprite_path("file/__core__/questionmark"))
TRUE --as expected

Code: Select all

/c game.print(game.player.gui.is_valid_sprite_path("file/__core__/graphics/questionmark"))

posila
Factorio Staff
Factorio Staff
Posts: 5202
Joined: Thu Jun 11, 2015 1:35 pm
Contact:

Re: [0.16.36] Sprite Path from file not working

Post by posila »

The documentation is misleading (or rather wrong).
Sprite path of type file references files from scenario folder, its purpose is to be able to show some images in tutorials and campaign, without having to keep them in memory all the time. is_valid_sprite_path doesn't check if file exists in this case, because that is not deterministic.

You can access question mark through is_valid_sprite_path("utility/questionmark"), and I assume alien-artifact-goo is an item icon so you can access that through "item/alien-artifact-goo"

I fixed the documentation for next release

blueblue
Long Handed Inserter
Long Handed Inserter
Posts: 75
Joined: Tue Apr 11, 2017 7:39 pm
Contact:

Re: [0.16.36] Sprite Path from file not working

Post by blueblue »

The alien artifact icon is in base but only as an image file, not an item, which is why I was looking at file sprite paths in the first place. Since I am working with a scenario I'll look into how the tutorials are doing this.
unique_2 on discord and mod portal

sparr
Smart Inserter
Smart Inserter
Posts: 1327
Joined: Fri Feb 14, 2014 5:52 pm
Contact:

Re: [0.16.36] Sprite Path from file not working

Post by sparr »

So if an image file is not used by any sprite-ful prototype then to use that icon as a button sprite you might need to make a new item with a sprite of that file, then reference that item/itemname for your sprite?

Bilka
Factorio Staff
Factorio Staff
Posts: 3139
Joined: Sat Aug 13, 2016 9:20 am
Contact:

Re: [0.16.36] Sprite Path from file not working

Post by Bilka »

sparr wrote:So if an image file is not used by any sprite-ful prototype then to use that icon as a button sprite you might need to make a new item with a sprite of that file, then reference that item/itemname for your sprite?
No, you define a sprite: https://github.com/Bilka2/Quill/blob/master/data.lua#L3
I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.

Post Reply

Return to “Resolved Problems and Bugs”