Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines
(1 edit)

Okay, so, I found the part of the code causing the obvious harm (not to say there's not more to find; I'm currently testing a little at a time), and it's the "has" method.  Not sure if an issue with the distinction between Godot and GDScript, or between different versions of the engine or something, but on the bit I'm testing the error stops if I swap out a tiny piece of code.  ...and then I thought I understood the error, but the error comes right back if I correct it.  Here are the four versions:

1. if person.race.has("Elf"):
2. if person.race.find("Elf") >= 0:
3. if "Elf" in person.race:
4. if person.race.contains("Elf"):

First version fails (generates empty log), which led me to the second version (as it gets used in the code a lot), which lets the game load without an error.  But it feels inelegant, so I looked through the documentation and it says that the third one is identical, so I used that and it ran without error.

However, examining the documentation more closely, I realized that I was using an array operation when I should be using one for a string (so the third version might run without error, but it's not doing what I want it to do, and might still crash later).  So I found the "contains" method, which appears to do what I want.  However, when I use it in the code, we're right back to zero-content-log crash.

Is the second method really the only one that works??  I need to sort races into pools (Elves and Beastkin specifically), and it sure would be handy to ask the code if it has the little keyword in there, as opposed to "Does it have an Elf? Well, how about a Wood Elf? Well, how about a Dark Elf?" etc.  The "where do you find this substring?" method clearly does work, but it feels weird.

(1 edit)

Right, I forgot about the difference in engine versions. The game is essentially running on version 3.3 of the Godot engine, whereas the most recent version is 4.7.1, which includes a significant overhaul of the string variable functions. This is the relevant document for the game's string functions: https://docs.godotengine.org/en/3.3/classes/class_string.html. The string functions are still somewhat crude, so you will probably want to use the clunky #2 approach for most things. Alternatively you could use dictionaries to convert string keys into boolean values or integers, though it's really just pushing the bulk and work to somewhere else.

Godot is the game engine. GDScript is simply an abbreviation for Godot Script. Godot can run on other languages than GDScript, such as C#.

Oooh, that's a useful doc; thanks!

Oddly enough, despite it being less efficient than later versions, I do kinda appreciate having a version set in a given form.  Far too many things moving faster than my workflow can account for these days, so it's nice to have a thing where I can learn it at my own pace and not have to keep up with changes.