Example UI change

Noble Zarkon

Elite Quattromaster - Immortal (BTS)
Super Moderator
Hall of Fame Staff
GOTM Staff
Supporter
Joined
Sep 6, 2012
Messages
8,436
Location
Gibraltar
From thecrazyscot's mod, here are his changes to plot-tooltip.js to show (A) after the name of an ageless building.

JavaScript:
                            //TCS START
                            let ageless;
                            ageless = false;
                            for (const e of GameInfo.TypeTags) {
                                if (e.Tag == "AGELESS" && e.Type == info.ConstructibleType) {
                                    ageless = true;
                                    break;
                                }
                            }
                            if (ageless == true) {
                                buildingName = Locale.compose(info.Name) + " (A)";
                            }
                            else {
                                buildingName = Locale.compose(info.Name);
                            }
                            //TCS END
 
Sorry was trying to be helpful lol, really impressed with how quickly you got the Mod done.
Oh sorry, I didn't mean to come off as defensive - it's literally true haha. My programming language knowledge is - with the exception of a single Python for ArcGIS course for my MGIS - entirely self-scrounged. Python is something I'm pretty at home with, but I still violate conventions left and right because I'm not aware of them or don't understand their purpose. The funny (scary?) thing is that I know just enough to have become "that guy" at work, and have written several scripts which have ended up in Prod on client environments...:badcomp:

Everything I know about SQL I learned modding Civ5
Everything I know about Lua I learned modding Civ6
I've never even touched Javascript before, so everything I learn about it will be from modding CIv7 :lol:

All that to say...please tell me better ways to do things!! I know so little about JS that I don't even know what this
JavaScript:
GameInfo.TypeTags.some(e => e.Tag == "AGELESS" && e.Type == info.ConstructibleType)
returns...does it return an object? A boolean?

See? I really do know nothing lol.
 
So, did a little testing.

This didn't work:
JavaScript:
let ageless = GameInfo.TypeTags.some(e => e.Tag == "AGELESS" && e.Type == info.ConstructibleType);

But this works (returns an object or undefined):
JavaScript:
let ageless = GameInfo.TypeTags.find(e => e.Tag == "AGELESS" && e.Type == info.ConstructibleType);
 
It's possible that the JavaScript engine Civ7 uses doesn't support the latest features like Array.prototype.some(), which returns true if the passed function returns a truthy* value for any item in the array. It stops when it finds one or runs through the entire array if not. I'd go with these shorter functional helpers for frontend and backend code, but the for loop is ever so slightly faster. It's not a big deal typically, but it could add up in the game engine. Does the original Firaxis code use array functions or loops?

* Any value that casts to
true as a boolean, e.g. true, non-zero number, non-empty string, non-null object, etc.
 
Back
Top Bottom