Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

Hello again! I am back with what I hope is my final question lol! Using Godot 3 made all the difference and I've been doing a lot of Googling and experimenting and had a lot of success, but I can't seem to figure out a simple way to make the text under func initiate() play in a specific order rather than randomly each time the action is clicked. Is this a situation where there's not really an easy way to do this without changing all the code and the way it functions (like without having to change temparray to something like const)? 

(1 edit)

Quick tip, it helps if you reference a file name when referring to code so the other person doesn't need to hunt for it.

In the sex action files, the game uses 2 separate types of randomization; one is relatively easy to replace with a specific order, one is somewhat complicated to order. Changing temparray to const would have no meaningful impact on the behavior of the array, as it only prevents you from changing the type of the variable to something that is not an array; it does not prevent changes to the contents of the array. 


text += temparray[randi()%temparray.size()]

This selects a random line of text within temparray and appends it to the text return variable. To change it to a specific order, the simplest approach is to replace the random integer generator "randi()" with a persistent variable storing an incrementing integer. If we keep most of the function unchanged we get:

var count1 = 0
func initiate():
    ...
    text += temparray[count1%temparray.size()]
    count1 += 1
    ...

However,  many sex actions use multiple layers of appended text to the text return variable and reusing count1 for every layer can restrict the number of combinations of text generated if the layers have the same number of lines of text in temparray. To fix that specific case we can use conditional increments.

var count1 = 0
var count2
func initiate():
    ...
    text += temparray[count1%temparray.size()] 
    count1 += 1
    temparray.clear()
    ...
    text += temparray[count2%temparray.size()]
    if count1%temparray.size() == 0:
        count2 += 1
    ...

The second type of randomization uses specific characters to mark the beginning, separations, and end of the set of randomly selected text:

{^gently:tenderly:carefully}

The first two characters "{^" mark the beginning of the randomized text, the individual texts are separated with colons, and the end is marked with another brace. This sounds straightforward and you might be tempted convert split those three words into separate lines to be handled by a layer of temparray, but consider this line from 100caress.gd:

temparray += ["[name1] {^gently:tenderly:carefully} {^stroke:fondle:cuddle:massage}[s/1] and {^caress[es/1]:rub[s/1]} [names2] [body2]"]

This single line provides 24 unique combinations of randomized text.

The code for this process is found in func splitrand(text) of sexdescriptions.gd. If we made the incorrect assumption that there are a minimal number of cases where these random sets of text are identical, then it's possible to use dictionary to implement an incrementing integer strategy similar to above.

var dictCounting = {}
func splitrand(text):
    var pos = text.find("{^")
    while pos >= 0:
        var targetText = text.substr(pos, text.find("}", pos)+1 - pos)
        var splitText = targetText.substr(2, targetText.length()-3).split(":")
        text = text.replace(targetText, splitText[ dictCounting.get(targetText,0) % splitText.size() ])
        dictCounting[targetText] = dictCounting.get(targetText,0) + 1
        pos = text.find("{^", pos)
    return text

It's been a while since I've coded, but I'm mostly certain this would work as long as I didn't make any typos. While this is an inaccurate solution as the assumption was incorrect, it's by far the least effort solution.

If you want any more control over the ordering of text than this, then you will probably have to create an array of all possible combinations of text for each sex action and then use the incrementing integer technique to walk through them one at a time.


Edit: Please note that itch.io converted all tabs to spaces, which will wreck havoc in Godot if you try to copy and paste my code.

Thank you so much for taking the time to type all that out! And apologies for not referencing the file name, I was trying to ask in a way that would hopefully be less work to answer but ended up doing the opposite and oversimplifying.

I was just not understanding what I needed to do with randi() and using count1 worked perfectly for what I needed. Thank you!