It's time.
Let's get down to business:
For this project, I won't make the window so small. I'd also like to properly implement the box containers which allow you to change the size of the UI quite easily (at the cost of some up-front time-investment.)
You'll notice that everything is blue again - that's because I'm using my laptop to develop this, this time. We'll see if that makes the editor more friendly. My laptop is only slightly stronger than a raspberry pi, unfortunately.
I whip together the main scene I want to have. I title it "ground" and imagine it should have a grassy texture, and perhaps - a piknik blanket.
We'll have a "LineEdit" - which is the sort of text box like a username/password input or search bar. Only one line. Then the two buttons - randomize and enter.
I add a label at the bottom that we can put an error message in - if the player tries to enter a non-six letter word, we can give them a friendly reminder here.
Pleasantly, LineEdit has a feature to limit text to a certain number of characters. Any characters pressed after the 6 is filled will be ignored.
And...because I'm a god-damn psychopath - let's...do this.
I toss a script onto the ground scene and connect up the buttons. I don't know if I showed it last time, but every node has a set of signals they produce, which can conveniently be connected into code. They have quite a few options - but pressed() is enough for us.
And those become functions ready to go:
delphonso don't do this. You're a monster.
We get two new variables here: record, which is a blank dictionary, and vermin which is a very long string of 6 letter words. We'll talk about that later. My plan for the dictionary is simple - as far as I know, hashes are specifically designed to not be reverse-engineerable. That means, you can turn strings to numbers, but can't turn those numbers back into strings. However, if we keep track of all the strings and numbers (in our database), we can match them back up later if we end up with only a hash and not the string. I'm not sure if this will be necessary in the future, but I figured I'd get ready for it just in case. We might even end up making a reverse-engineerable algorithm instead.
[I missed a screenshot here, woops]
func _ready():
vermin = vermin.split(" ")
for n in vermin.size():
record[vermin[n]] = hash(vermin[n])
linein.text = vermin[randi()%vermin.size()]
The split(" ") here is just simply making the long string into an array, cutting out all the spaces and leaving us with only the 6 letter words. It's a bit easier on me than following the array syntax.
then, we go through the array and add each bug-word to the record dictionary, connected to its respective hash. Finally, we add a random word to the text-input box because it looks a bit nicer.
Let's give it a shot.
Uhhh what the fuck?
Well that's a nightmare. I'll deal with that in a second. Why does it look like a weird meme? At least the other stuff works. I added print(vermin) and print(record) to the end of the ready function. Here are the results.
Hmm. Some of the hashes are of different sizes. This is to be expected, but I'm not sure what that will mean for making stats from those numbers. Number lengths seem to vary between 8 and 10, mostly favoring 8.
Okay, well...deleting that text box and adding a new one with the same name fixed it. I also enabled the feature which allows you to easily clear the box by pressing the x.
For the reroll button, we'll just do the exact same thing we did in the ready function.
For the commit button, I think we'll probably need a new function there. So let's just set that up.
Okay, let's get started on that. First things first, let's make sure it's a six letter word.
If it is six characters (this won't care about if those are punctuation, numbers or letters, right now), we make a new bug and we run the randomize button to refill the box with a new bug (I might change this, in case the player want to just add like...20 jeremies or something.)
If not, the text is ignored, and the label we set up earlier will say "six letters, please". Then I create a 3 second timer, when that counts down, the warning message returns to "" - meaning nothing is shown and the box is effectively hidden. I then have to free the timer, otherwise we'll end up bloating the scene with timers if you keep putting in non-six-letter words.
This is all fine and dandy, but we need some bugs, man.
Let's work on the newbug function. I changed the above text so that the commit button send the inline.text to the newbug() function, thus you'll see the new variable: newguy here.
[I also missed this screenshot]
func newbug(newguy):
if newguy in record:
print("already got it!")
else:
record[newguy] = hash(newguy)
vermin.append_array(newguy)
print("new bug added to record")
Pretty self-explanatory. If newguy is already a bug we've seen, nothing happens. We can be sure that the text coming in is 6 letters, so we don't need to check it here again. If the word is new, we add that to the record (with its hash) and append it to the array. Should be easy!
Cool - checking if the bug is already on record works no problem. Let's add a new bug..."fucker"
You motherfucker.
This was actually a very dumb mistake on my part. "append_array" does not append the array - it appends
an array onto an array. The function is simply "append()", so it looks like this now instead:
vermin.append(newguy)And with that:
It works! We're now creating hashes and adding them to the record - the game is also adding those words to the list that it can randomly roll. Nice!
Here, I pressed random until the word I typed in showed up, confirming that it is working as intended.
But still. We need a bug. I think the best way to do that is to make a new scene.
A new scene: insect. As of now, it consists of just a sprite and a label.
At the beginning of the program, we get ready to instance it. And then we go to the newbug() function and add the following:
A new bug is added, then added to the scene tree. Their name is whatever name was passed to commit, and they're dropped into the window somewhere (randomly within screen size, for now - a +50 was cut off at the end, with the goal of running a 25 pixel barrier along the top, so that we don't get bugs on top of our buttons.
Let's try it out!
It's beautiful
We are already approaching the desired result:
I ran a few more 6-letter strings through to see what sort of hashes we can expect to see. Many of them start with 4, which is interesting.
-=-=-=-=-
A few additional notes: Here's the quick and dirty method for matching hashes to their original strings.
I was also thinking about bugs and I would love it if I could get them to walk in a sine wave like how many ants and cockroaches usually forage:
SARGE SARGE THEY'RE ALL OVER ME
I checked the capumon code and you should be able to get about 25% crit chance at maximum - which is pretty low, considering most combats end within 6 turns. If you have a cactus in your party, you crit chance lowers, but your accuracy greatly increases.