Text Adventure : Help Needed

Sheparoo
20 Aug 2018, 13:18

Hi!

I'm not very good with code stuff and I don't understand the vocab of it very well, but I'll do my best to explain what I want to have happen.

I want the player to choose to be a male or female character in my game. I already learned how to do this by inserting {player.gender} into script, but I'd like to expand on the gender selection by inserting some sort of "if" "then" script. If the player chooses to be male, for instance, I'd like them to be referred to througgout the game as sir, or Mr., or guy/dude/etc.

Any way I can make that happen?


mrangel
20 Aug 2018, 13:44

In the text processor, you could do this using "either". For example, you could put: {either player.gender="male":Sir|Ma'am}.


Selsynn
20 Aug 2018, 14:11

i don't know if there is another method, but it's very simple.
You will need to post the code in the if section, exactly. Use the GUI to be more sure of what you do.

  1. First, you will need to ask your player. You can ask by a 'get input' or by a menu, and store in an attribute
    I suppose you have done it like the tuturial Character creation, with a menu:
show menu ("Your gender?", Split ("Male;Female", ";"), false) {
    player.gender = result
}

I removed all the elements that we don't need presentment. I hope you recognize the code

player.gender contains, when the player has finished it's character creation "Male" or "Female"
If you used it now, You will have, for exemple when the player meet a new person.
"Male, I'm the new neighbors" or "Female, I'm the new neighbors"
It's not very good, no ?

  1. Change Male by Dude/Guy/Sir... and change as the game progress.
    Yes, there is again two method to do it. You can fix it in the start of the game, or you can allow that to change as the game progress.
    To allow changing as the game progress, you will need a function. It is a system to not repeat a lot of time the same line.
    You will see the Function menu near the end of the list of your objects. (go to http://docs.textadventures.co.uk/quest/creating_functions_which_return_a_value.html if you're not sure about creating a function )

2A) Creation of the function

Go for it, and create a new one. Name it as you want (like "PrintGender").
Your function will return a string, that means some words, that you just have to print in your message.
The code will be this one at first. You can change it when you want.

if(player.gender="Male"){
    return("Sir")
}else if(player.gender="Female"){
    return("Madam")
}

It is the basic skeleton to be functional. It will return "Sir" if it is a Male, and "Madam" if it is a Female.

2B) Usage of the function
In your adventure, whenever you want to print Sir Or Madam, you just have to call function by the GUI and give it your name to use it.
exemple :
I met a new person on the road. "Hi", I said, "who are you ?". "{PrintGreeting()}, I'm one of your new neighbors !"

It should display if it is a Male
I met a new person on the road. "Hi", I said, "who are you ?". "Sir, I'm one of your new neighbors !"
or if it is a Female
I met a new person on the road. "Hi", I said, "who are you ?". "Madam, I'm one of your new neighbors !"

Is the objective get ?
Why a third point will you ask ? Because, one day or another, you will need to have different reaction from different type of character the player meets. How to do it ?
You will have to go to your function and complexify a little

  1. Overriding the default value of the function
    When it is the father/mother / brother/sister / or best friend, thing will change. It will be very strange your bff say to you "Sir" or "Madam", don't you agree ?
    You will notice in the GUI of your function, the possibility to add parameters. There you can define your overridingMale, and overridingFemale title. (Remember the order, though)
if(player.gender="Male"){
    if(Trim(overridingMale)=""){
        return("Sir")
    }else{
        return(overridingMale)
    }
}else if(player.gender="Female"){
    if(Trim(overridingFemale)=""){
        return("Madam")
    }else{
        return(overridingFemale)
    }
}

We have tested if the parameter has something, and if it has, we return this parameter. Else, we stick with the default case

exemple 1 :
I met a new person on the road. "Hi", I said, "who are you ?". "{PrintGreeting("","")}, I'm one of your new neighbors !"

It should display if it is a Male
I met a new person on the road. "Hi", I said, "who are you ?". "Sir, I'm one of your new neighbors !"
or if it is a Female
I met a new person on the road. "Hi", I said, "who are you ?". "Madam, I'm one of your new neighbors !"

exemple 2 :
I met my brother on the side of the road. "Hi Greg", I said, "what are you doing ?". "{PrintGreeting("Dude","Sis'")}, I'm on my way to school, want to join me ?"

It should display if it is a Male
I met my brother on the side of the road. "Hi Greg", I said, "what are you doing ?". "Dude, I'm on my way to school, want to join me ?"
or if it is a Female
I met my brother on the side of the road. "Hi Greg", I said, "what are you doing ?". "Sis', I'm on my way to school, want to join me ?"

Better, don't you think so ?

@mrangel
Oh either ! I didn't knew about it. Cool !


DarkLizerd
21 Aug 2018, 02:44

In my Adventure game (Basic, not Quest) I did it with a function I called pronoun...
IE:
msg ("I told you to get " + pronoun(0) + "!")

then the function:
(In Basic-Quest mix, but you should be able to understand)

<function name="pronoun" type="str"
if (player.sex>"Male") {
PN=Split("him, his, he, boy, man, bro", ",")
}
else {
PN=Split("her, her, she, girl, woman, sis", ",")
}
return (StringListItem(PN, #))
// ok, I don't know how to return the selected entry, but I hope you get the idea...

Now, when you write the line needing the player sex, just select which entry you need,
IE:
you need "boy or girl" then use pronoun(3)
msg("What a good " + pronoun(3) + "!")
"What a good boy!"
"What a good girl!"


Watcher55
21 Aug 2018, 10:33

You can also, having determined the gender, set the relevant player attributes like player.pronoun, player.possessive and so on, so in your scripts you can use those attributes without calculating them each time.