#Icon Badges Installation / Troubleshooting
1 messages ยท Page 1 of 1 (latest)
oooh, cool
What have you done so far, and what are your goals?
honestly just wanna add my own IB's, and change vanilla ones to fit my mod
i tried a couple things to no avial, but this is what i had last
Do you want to use csv-style tables for the data, or Lua?
Do you want to have user settings for language, eg Fe vs I for iron?
You need to call BuildBadge.
It's been a while, so this is a good test of the documentation.
uhhh, which one is the one above (CSV/lua)
and the bottom one, i havent really touched settings so im gonna leave it
That's Lua. It's a good choice if you don't have too many icons to deal with.
Ok, so we'll use Icon Badges without the IconBadgesGroups additions.
sure
and yeah, like it'd be around the same as normal IB calls which is where i got that code from ๐ญ
Galdoc's instructions miss a key step.
~~what is that key step ๐ญ ~~
Build_badge( prototype, ib_data)
prototype = data.raw.ammo['high-densith-magazine']
local ib_data = { ib_let_badge = v.badge, ib_let_corner = 'right-top' }
Reverse those lines.
IIRC Build_badge is a global function, so no fancy steps to be able to access it.
Reverse the lines. I did them in the order I thought of them.
Yes.
cool
How much programming do you do? So I know how much to break it down.
...
i know jack about using lua, or scripting
i dont program much apart from using the API ๐ญ
Ok, I won't assume much then.
I'm the one who turned his ingredient definitions into functions so he could continue using the shorthand with 2.0 removing it
exactly
Shifting to notepad for thinking out loud, then.
๐ญ all good
NP. We have to start somewhere!
exactly!
If we don't start where we are, then it's really hard to move forward.
ofc ofc, completely understand
wait, because it has prototype = data.raw.blah.blah["high-density-ammo"], does that mean i have to do that for everything i wanna add IB's for?
typing out an example in notepad. I do it in a strange order, confusing to others.
e.g
prototype = data.raw.ammo["ammo-name"]
prototype = data.raw.item["item-name"]
etc etc
its all good
-- DRAFT!!!!
my_data =
{
{type = 'ammo', name = 'pm-high-density-magazine', badge = 'HDR'},
{type = 'item', name = 'iron-ore', badge = 'I'},
}
for _,i in pairs(my_data) do
Build_badge(data.raw[type][name], badge)
end
@brittle geyser Does that look right?
imagine it needs penny-inatoring 
I'm just going to complain before I interpret that
To access a prototype in data.raw, you need to give the type and the name.
oh yeah, i know that
Make it a lua code block so it actually is readible D:
you're a lua code block :(
(Did it myself)
my_data =
{
{type = 'ammo', name = 'pm-high-density-magazine', badge = 'HDR'},
{type = 'item', name = 'iron-ore', badge = 'I'},
}
for _,i in pairs(my_data) do
Build_badge(data.raw[type][name], badge)
end
I often make silly typos, and don't have it setup for easy testing.
LOL, seconds after I fixed the original.
๐ญ
Yeah, that would work.
You just need to do i.type and i.name etc..
i keep the ib_data still below it all, right?
Right! I forgot he changed it to ib_data.

my_data =
{
{type = 'ammo', name = 'pm-high-density-magazine', ib_data = {badge = 'HDR'} },
{type = 'item', name = 'iron-ore', ib_data = {badge = 'I'} },
}
for _,i in pairs(my_data) do
Build_badge(data.raw[type][name], badge)
end
let me edit that
aight
That should be it. I'm going to mark earlier versions as drafts, to avoid confusion for anyone reading later.
fair enough ๐ญ gonna test it rq, but if it works thank you so much
Are there any parts that aren't clear? It's best if you understand each layer.
oh no, i essentially get that
There's also a way to tell it to ignore the vanilla set it comes with.
the only thing i dont understand doesnt really matter to what we are doing ๐ญ
oh yeah, saw that
Be sure to count the {}.
i can hear penny mentioning the nesting, a distant scream a continent away /s
And Black. do you want me to turn that into a function like this?
PM.badge(type, name, letters, position)
Of course it'll in effect just be this:
-- Things are not final since I don't know about how icon badge works
function PM.badge(type, name, letters, position)
if not mods['icon-badge'] then return end
if #letters > 3 then error("Badge can only be up to 3 letters long") end
if position and valid_positions[position] then error("'"..position.."' is not a valid position") end
Build_badge(data.raw[type][name], {
badge = letters,
position = position,
})
end
uhhhhh, idm, its really up to you
it means nothing to me which i use ๐ญ
both are equally usable
(also I'm going to again mention that vencord's ShikiCodeBlocks are fantastic)
That should work. I used to wrap Build_badge in pcall(), but now it's pretty stable.
pretty
Alright, time to pull my local copy up to date with PM
:(
Your formatting makes me unhappy
HAHAHAHA
Icon Badges Groups adds the ability to change language (eg Fe vs I), and csv-style data which is easier to edit.
Do the formatting BlackATM is used to.
I'm just upset about trailing whitespace
you see the difference though right
I've wrote some regex to remove all that at one point
Yeah, and I don't know what setting I have to complain about it while yours doesn't
I used to be upset with the almost-empty lines, but brackets not lining up is worse. That might change if I give the new built-in rainbow indents a chance.
....do i need to make the file required by a data- file? ๐คจ
The automatic formatting, ctrl-shift-f , removes trailing whitespace if the syntax is correct.
Is it in its own file now? If so, you need to require it in one of the data stage files, after all the icons are made.
The program only looks in data, data-updates and data-final-fixes. It won't look anywhere else unless you tell it to.
Btw I'd personally put it in compatiblity for sorting
true
Before going back through it with auto-formatting. I need to figure out how to tell it how we want it formatted
I know when I went throguh it first, it turned {"something", "else"} into { "something", "else" } which annoyed black
it said to put it in final-fixes, right?
...did it 
i dont remeber ๐ญ
To change that, you'd need to know more about VSCode than I do. It would also make their install non-standard, and harder to trouble-shoot.
fair enough
In this case, it was easier to retrain my brain than change how it displays. I'm new enough at it that I want to keep my installation as standard as possible so it's easy to get help.
Other things, though? My brain refuses to retrain.
(this means nothing to me, i have no idea what that is telling me ๐ญ )
yeah, mood
should be ipairs ??
I keep confusing pairs and ipairs, and use trial-and-error.
๐ญ lmao
(use your imagination to imagine the same code as above, but with i. next to the three things mentioned)
oh wait, ipairs
No, ipairs should not have an effect here
They are functionally the same in this instance, and the recommendation is to use pairs since it's faster
Oh it's now i.ib_data not i.badge
You see how your data defines the type, name, and ib_data?
That's what you're indexing into
yeah
cool
so what is the difference between ipairs and pairs
๐คจ
...do i need to actually make it not the vanilla preset for it to work? because still nada ingame
ipairs is meant for arrays, and the order of pairs is comparatively random
Factorio has changed pairs to be determinsitic and will always be identical to ipairs for any index up to 1024
pairs then falls back to insert order in factorio, meaning if only add elements to the end of the array, it's still the same even after 1024
This is different than raw lua, where it's iterated over in hash order. Which is effectively arbituary and random.
Which, again, factorio is meant to be deterministic so that was rejected and replaced
Yeah, I was confused for a moment, thinking of how Python does it. (Why? I haven't used Python in years.)
(And I probably remembered it wrong.)
i learnt 2 years of python and dont remeber a lick of it
as soon as i left high school, immediantly dumped out of my head
gone with the wind ๐
Leavnign the vanilla preset is fine if you don't delete any vanilla prototypes. It might crash if it tries to put a label on something that doesn't exist.
show us the current code again
Add line (such as local b = 1 ) and a breakpoint after Build_badge call.
Then hover over the variable i, or add it to the watch screen and see what it says.
Change that ... add a break point just before Build_badges so we can step into it if needed.
Is pm-high-density-magazine ammo, or an item, or something else? I just assumed it was ammo.
Does the recipe have its own icon, or does it inherit it from main_product?
If it wasn't an ammo, it would having an error about indexing nil
uhhhh
its an ammo, recipe uses the icon of the ammo
the iron plate doesnt change aswell, i just havent screenshotted it ๐ญ
(as in it just defaults to it, i havent set it as anything)
(you're not stopped at the breakpoint, so these are just luals's guesses, maybe nto actual values)
also is the warning on that function call relevant?
Build_Badge? undefined global "Build_Badge"
also im gonna be honest, i have no idea what the first half of that means ๐ญ do i move the breakpoint up or?
Hard to say about the warning. Build_badges is working for the vanilla items, eg Piercing Rounds.
Build_Badge is not the same as Build_badge
Argh, I"m typing too fast, not cross-checking.
....
hmmm
that
might be an issue
No s. There is no Build_Badge, or there shouldn't be.
its still an undefined global but least its capatalised!
I think it will always be an undefined global unless you have icon badges as an open folder next to it
probably ought to do that so it can be more helpful
From Icon Badges mod, data-final-fixes.lua
-- Generate letter icon Badges
-- ***************************
-- Prepare badges for Vanilla
require("vanilla")
-- Iterate over all vanilla items from above and build badges for each
if Ib_global.badge_vanilla then
for subListName, subList in pairs(Badge_list) do
for itemName, ib_data in pairs(subList) do
if data.raw[subListName][itemName] then
Build_badge(data.raw[subListName][itemName], ib_data)
end
end
end
end```
but mostly it seems like you just need to run in debug and see what's happening when it goes wrong
would it matter that im testing this in editor extensions? i doubt it, but might aswell ask
Luals :(
That's just plainly wrong :(
AHAHA
gotta love luals
also, for the life of me i know i set up a debug factorio thingy but god knows it doesnt work now ๐ญ
I don't think the inner brackets should be there.
shouldn't matter, parens around any single expression is no-op
Gotta love Lua syntactic sugar. There are so many ways to write the same thing, I'd get caught up in that instead fo the real problem.
Like you know there's multiple...
if i push this to main, will it fuck with you rn ๐คจ
Nah
I'm just touching the library (and removing some errors in entity.lua from luals just not being that smart and narrowing)
๐ญ
@brittle geyser How easy is it for you to look at what he's done? I'm not set up to test it.
...should i be using ib_let_badge?
Easy, I just gotta merge upstream main back into mine
(I probably should learn how to rebase my commits though)
(LOL -- I just got started with local Git, and yesterday forgot to start a branch for the day. Trying to merge at the end of the day was interesting.)
oooof
Btw Black, where are you requiring the icon-badges file?
Ah I see it
Good catch!
should i switch the badge in the {{}} or the ib_data?
Is he making any changes to icons after data.lua?
Not that I know of
Explain to me what each bit of code does. It might take you a few rounds or spiral levels. I'll play rubber duckie.
Icon Badges just adds a layer to icons (and converts icon to icons if needed).
the ib_data presumably says "hey yeah, this shit needs a badge" and then badge... is the badge you can give it? ๐คจ
(So many variations in icon and icons and layers and shortcut formats!!)
What are the parameters for Build_badge ?
Close, but it' s not type and name.
๐คจ whuh
I feel like I need to get galdoc to become an annotation fanatic like I am
The parameters are separated by commas. There are two of them.
The first one is
data.raw[i.type][i.name] . That's the prototype. It's one thing.
Layers on layers on layers. Not easy to break apart, but you eventually get sort-of used to it.
woo!1 being worn down by systems!! just like real life!!
What's the second parameter?
Copying the line so I don't have to keep scrolling up.
Build_badge( data.raw[i.type][i.name] , ib_data)
For the first time through the loop, where is ib_data defined and what's its value?
uuuhhhhhhh
It's a bit tricky, since it's a table, not a simple value.
it's i.ib_data
yeah, wanted to say that
So it's also in the my_data object
Now work up. What's it's actual value?
the.. first thing in my_data? (HDR)
Almost. It's actually the table { badge = "HDR" } Which is wrong. Unlike me, you read the docs, and found it should be { ib_let_badge }
Do you know how tables work, and get passed? They're a bit unusual.
Everything inside the { } is considered one thing. In this case, it's just the name ib_let_badge and its value.
Does factorio load icons before trying icon and icon_size?
It could be more.
ib_data = { ib_let_badge = "HDR", ib_let_corner = "top-left" }
:(
PM either has another file not in git or something broke
whuh
OH
HR
loser
I don't know. Icon Badges should work with any size icons.
LR users rise up
No i'm entirely talking about how it leaves the icon and icon_size field unaffected, while injecting things into the icons field
I think that's the wrong path. Does __base__ doesn't have hr-lithium-battery ?
It's not even looking in base so idk
I'm just commenting out hr to see if it works
Strange. The error says it's looking in __base__
Yeah, and it has non-hr
oooh
What's hr?
Oh no yeah
You learned a lot today!
i did
Make sure you get a good night's sleep to consolidate it.
oh i will, just finished my first week of college and already behind on work ๐
Alright.. time to start telling you about every high resolution image that's failing :)
Then try something a bit more difficult. (Then work on other things, come back to this, and realize you've forgotten everything. You'll learn it faster the second time.)
how tf is that even failing??
mood, big mood
i.. forget an i in molteninator
The first dozen times through it can be discuoraging if you don't expect it.
See also Adam Savage's video on post-project depression.
i will, ty
I have a feeling I can figure out why
but also, HUGE mf'ing thank you dudes
my ass would have never figured this out on my own ๐ญ
moltin / molten e/i
me very smort ๐
Entirely selfish on my part. Paying it forward, and teaching is a good way to learn/reinforce/find gaps in understanding.
oh yeah ofc
i do have one thing though, it doesnt seem to be changing the iron plate badge ๐คจ
May also be procrastinating from my own project.
Add a break point inside the loop and make sure it's looping.
Add a dummy line where you want the program to pause, eg local b=1 . Keep the cursor on that line and press F9, or move to the far left and click, to get a red dot in the margin.
Breakpoints are a very important tool in debugging.
Type a variable name in the watch window. Taht's another important tool.
Since iron-ore is a vanilla item, and you haven't turned off Ib_global.badge_vanilla , it might be doing both the vanilla badge and your badge, one ove rthe other.
Try moving yours to another corner.
I mean, the base game seems to be adding the icon badge to iron plates at final-fixes while you're doing it in data...
ore or plates?
Icons for the recipes are being shown. So far, we've only changed hte icons for the items. It might be using the main_product's icon instead of the recipe's icon. Doing both HR and LowRes adds another layer of potential mistake.
Hmmm, how does Build_badge know if there's already a badge?
i presume it checks the item two times, then goes "already has a badge? aight, leave it"
checks when base loads, then when PM loads
I think that note is from the older version, back when users added properties directly to the prototype instead of using a function to just add layers to the icon.
@vast surge See #1283843931808858163 message onward . Thoughts?
I'm pretty sure now it just adds layers to the icon.
Build Badge doesn't check for anything, I don't think
If you call it, it'll just add what you tell it to add
So that bit of the doc is out of date?

what?
They haven't de-activated Ib_global.badge_vanilla , so it's probably putting the vanilla badge on, and his badge.
i mean, i am ahppy to just disable the vanilla preset and do the pre-existing stuff myself, i need to change it anyway ๐ญ
(Or they're dealing with main_product or HR/LR .)
Oh
May as well disable it now, get that bit out of the way.
Build_badge is just a function that adds a badge, that's all. It's what's called over and over again in the Process Badge List function
The note implies we don't have to disable badge_vanilla . The mod somehow knows that we already added a badge.
lemme see
@rancid minnow Try setting Ib_global.badge_vanilla = false in data.lua .
aight
hm
ait, in the file itself? data.lua?
The mod page doesn't mention Build_badge at all.
Hmmm, the way you suggest doesn't need it.
@rancid minnow I may have steered you wrong. I showed you how I do it, but Galdoc's way also works. (He wrote the mod, so his way should work!)
The way I do it also works, but combining the two ways won't.
meh, im all good
aslong as it works and wont cause any issues
also, the disabling thing worked all good
time to rewrite it all!!
As an exercise, compare what we did to the instructions here
https://github.com/Orion351/item-badges
Or not. It depends what you want to work on next.
Now to stop procrastinating on Nullius BioScouts.
good luck dude
If you need help setting it up, poke me tomorrow and I'm happy to go over it on stream
if Ib_global.badge_vanilla then
if not mods["galdocs-manufacturing"] or (mods["galdocs-manufacturing"] and Ib_global.activation) then
Process_badge_list(Ib_global.Badge_list)
end
end
Basically, if you want to run your own badge list, just set Ib_global.badge_vanilla to false, and that won't run. Then just build your own badge list manually.
We did it a bit differently, calling Build_badge directly, so beware of confusion.
and run Process_badge_list([your list])
yah
I wanted Build_Badge in there cuz I use it for GM vanilla
And you can too if you want
Doesn't Process_badge_list specifically take a dictionary of lists?
It just adds little metal plate .pngs to the corners of some recipes
It takes a badge list specifically
I use it for IconBadgeGroups , but in hindsight I might have been able to make a list in the right format to use Process_badge_list instead of making my own loop. Not a big deal.
Then I must've looked at the wrong function..
-- Badge List Functions
-- ********************
-- This is an optional structure to facilitate easy badging of prototypes. It's what I used for my vanilla badging.
-- Modders may use it too if they wish, or instead use the individual function above.
-- The format for a badge list is:
-- badge_list[prototype_group_1] = {["prototype_name_1"] = ib_data_1_1, ["prototype_name_2"] = ib_data_1_2, ...}
-- badge_list[prototype_group_2] = {["prototype_name_1"] = ib_data_2_1, ["prototype_name_2"] = ib_data_2_2, ...}
-- ...
-- where:
-- prototype_group is either fluid, recipe, item, or child-of-item in data.raw
-- prototype_name is the name of a fluid, recipe, item, or child-of-item in the prototype_group
-- ib_data_whatever_whatever is a table with icon badge properties as outline in the readme
-- Merge Badge List
-- NOTE: To remove a badge from list1 (i.e. un-badging an item from vanilla), simply set the ib_data = {} for that entry
-- WARNING: Using this function will overwrite entries in list1 with entries from list2!!!!
sorry -- badge list in that context meant that data structure there
not a flat list
Now I remember why I did it my way. I wanted to group all iron (copper, silicon) things together, instead of all recipes (items, ammo)
It's a table of {string|table} pairs
yah, that's entirely up to you
that's the other reason I split out the 'build badge' fucntion, so people could organize it how they wanted
Just be sure you know what BlackATM has before starting to change it, to avoid confusion.
Comment out all but a few lines in my_data.
Use the watch window to see exactly what you're sending to Build_badge .
๐คจ
That doesn't matter unles you've unzipped IconBadges and added it to VSCode.
VSCode can't read zip files, or even unzipped that it doesn't know about.
i think i found the error
(It depends what folder you put VSCode in. It might already see it.)
so, a code name in my mod uses '
trying to input that into the icon badges breaks it, because it also uses '
and i presume, because the names arent the sames and therefore is badging something that doesnt exist
its throwing a hissyfit
You can use ' or " in Lua, but need to make sure they match. Other languages are different.
thank god ๐ญ
https://www.lua.org/manual/5.2/manual.html#3.1:~:text=Literal strings can be this really ought to be a subheading to itself...
I've got VSCode up, and can share my screen if you want to see breakpoints and watch window in action.
uhh, sure
sorry, was making sure everything was spelt correctly
hold on
i think it might actually because i had non-existent shit in there
letting it load rn ๐คจ
yeah no, it now loads fine ๐ญ
Make a note of taht technique. I had a list of stuff like that (which I lost, sigh).
oh i will, defintely
oh yeah no, i do not have the social or mental capacity to actually talk on call rn ๐ญ
mhm
ty
and yeah, i can
mhm mhm
i so need to reset that up
i knew i had it, but not anymore ๐ญ
mhmh mhm
i mean.. hm
i understand everything you said ๐ญ
idk, i get it??
This sort of thing takes practice. It's like walking. Theory and demonstrations are good, but you need to actually do it.
oh yeah i completely get that, its how i even learned the API
just keep doing it, and you get it
I'm stil learning the API.
i mean, im happy to help if your struggling with something
I'm here most days, if you have questions.
I'll ask if I need help. Right now I'm building up my mod in tiny steps, learning as I go.
oooh, nice nice
I"m paying it forward. jarg and codegreen and the others have been a big help to me.
i've always wanted IB functionality and now i finally got it
oh same, ofc
they do a great service in #mod-dev-help
And if I can't pay it forward here, I pay it forward in other groups, eg knitting
Sometimes it takes a while before I can, but it balances over a lifetime.
mhm mhm, the ability to pay it forward arrives when it arrives
you find it eventually
does ib_let_inverse have to replace ib_let_badge or is it an extra thing that goes in the ib_data table?
nvm, figured it out
yipee
Yeah
Just put a
if not mods["icon-badges"] then return end
At the beginning
Like the rest of your compatibility files 
Yeah
It basically just says, hey does the mod we care about exist?
No? Okay then fuck off
data.lua?
Yeah, this line should be in the icon-badges.lua file...
Move it >:(
This is not your place Ib_global.badge_vanilla = false
That flag tells Icon Badges to use its own built-in badges for everything that's in vanilla. If you want to put different badges on things that exist in vanilla, you need to make the flag false, and do them all yourself. (You can copy the vanilla set and edit it to save time.)
The issue is where he was setting it false
You see the compatibility require right above it?
That contains the logic for not running when icon badges doesn't exist
compatability -- is that part of BlackATM's mod? If I read the require statement right, it is.
yeah
Yeah, Ib_global only exists if IconBadges has been loaded.
(Also I might go through and reformat Black's Icon badges to use the official list syntax that I made a pr to annotate into a proper class)
Yah, that looks right to me

