Deriving player.species from player.home variable

BlunderingFool
26 Jan 2014, 14:14
So after fiddling with various setups for about an hour I'm rather stumped. Being new to Quest I've been struggling even with the help from the tutorials on the wiki to make it so if player.home = Village (For example) Then player.species should be set to Human.

Currently I've been clipping the code back in the character creator to just after the player.home is set so everything is clean and working so far, I just need to know who to set one variable depending on what another is. :?

My code so far is as follows.
msg ("You feel as if you are falling...<br/><br/>A voice calls out to you...<br/><br/>What is your name, travler?")
get input {
playername = result
msg ("\"You have left the mortal coil\" + player.alias \" however I am willing to send you back.\"")
ClearScreen
ShowMenu ("Were you a man or a woman?", Split ("Male;Female",";"), false) {
player.gender = result
ClearScreen
ShowMenu ("Where did you hail from?", Split ("Village;Mountains;Plains;Desert;Forest",";"), false) {
player.home = result
msg ("\"So you are\" + player.alias \"the\" + player.species \"from the\" player.home\"")
}
}
}

Liam315
26 Jan 2014, 14:35
You need to insert the code that assigns the species depending on the result of home. You can do this using if/else statements. Remember when writing conditions for if/else (or anywhere that uses an expression) that involve a string, always put the string in quotation marks if you are writing it directly (in this case, "Village", "Mountains", etc.)

msg ("You feel as if you are falling...<br/><br/>A voice calls out to you...<br/><br/>What is your name, travler?")
get input {
playername = result
msg ("\"You have left the mortal coil\" + player.alias \" however I am willing to send you back.\"")
ClearScreen
ShowMenu ("Were you a man or a woman?", Split ("Male;Female",";"), false) {
player.gender = result
ClearScreen
ShowMenu ("Where did you hail from?", Split ("Village;Mountains;Plains;Desert;Forest",";"), false) {
player.home = result
if (result = "Village") {
player.species = "human"
}
else if (result = "Mountains") {
player.species = "yeti"
}
else if (etc. etc.) {
}
msg ("\"So you are\" + player.alias \"the\" + player.species \"from the\" player.home\"")
}
}
}


The same thing can be achieved using the "switch" function, but if you're still learning Quest then it's probably better to stick with the if/else format.

I also noticed that you have "playername = result" and not "player.name = result" at the start of the code. If that wasn't intentional that will end up causing you errors as well.

BlunderingFool
26 Jan 2014, 14:37
Thank you for pointing that out, I'd have missed the player.name error. Also I did try if/else statements but it didn't work, I'll try putting every string in quotes.

[EDIT]

Tried it and it broke Split for some reason. I may look into doing it with switch instead. =/ Additionally + player.alias, + player.species, and + player.home aren't functioning as expected, not returning their strings for some reason. X.X

[EDIT]
Okay got split working but the previous problem of not returning strings remains.

HegemonKhan
26 Jan 2014, 15:20
can we see your new code, to look for your errors?

blunderingfool wrote:msg ("\"So you are\" + player.alias \"the\" + player.species \"from the\" player.home\"")


change it to this (you can adjust it's ending, as I'm not sure how you want it ~ hopefully you can keep it's syntax right, if not, I can help you with it):

msg ("So you are " + player.alias + ", the " + player.species + " from the " + player.home + ", eh?")


-----------------

also, getting the: msg (etc + "text" + Object.Attribute + etc), correct isn't easy...

----------------

http://quest5.net/wiki/Split

just to explain it's syntax:

split ("choice_1;choice_2;choice_3;etc" , ";")
~OR~
split ("choice_1+choice_2+choice_3+etc" , "+")
~OR~
split ("choice_1Xchoice_2Xchoice_3Xetc" , "X")

use this syntax though (lol):

split ("choice_1;choice_2;choice_3;etc" , ";")

Pertex
26 Jan 2014, 15:24
Could you post an example what you are trying to do?
Edit: HK was faster :D

BlunderingFool
26 Jan 2014, 15:30
Everything is working so far minus the + player.X statements and grabbing the species Human from the home Village may or may not work seeing as it won't return it's string.



msg ("You feel as if you are falling...<br/><br/>A voice calls out to you...<br/><br/>What is your name, travler?")
get input {
player.alias = result
msg ("\"You have left the mortal coil\" + player.alias \"however I am willing to send you back.\"")
ShowMenu ("Were you a man or a woman?", Split ("Male;Female",";"), false) {
player.gender = result
ShowMenu ("Where did you hail from?", Split ("Village;Mountains;Plains;Desert;Forest",";"), false) {
player.home = result
if (player.home = "Village") {
player.species = "human"
}
msg ("\"So you are + player.alias the\" + player.species from the + player.home\"")
}
}
}


Note I've tried using both message and expression for the printed message.

And yea if it helps any the player is supposed to start out being revived by a god or something (Character creation). You set your name, gender, and home and your species is selected based on your home.

HegemonKhan
26 Jan 2014, 15:32
I just editted my previous post, refresh and look at it (sorry for the inconvenience).

--------------------

Edit: and now this one~post too, I editted... lol...

from your code...

msg ("You feel as if you are falling...<br/><br/>A voice calls out to you...<br/><br/>What is your name, travler?")
get input {
player.alias = result
msg ("\"You have left the mortal coil\" + player.alias \"however I am willing to send you back.\"")
ShowMenu ("Were you a man or a woman?", Split ("Male;Female",";"), false) {
player.gender = result
ShowMenu ("Where did you hail from?", Split ("Village;Mountains;Plains;Desert;Forest",";"), false) {
player.home = result
if (player.home = "Village") {
player.species = "human"
}
msg ("\"So you are + player.alias the\" + player.species from the + player.home\"")
}
}
}


change it (or just copy and paste, lol) to this:

msg ("You feel as if you are falling...<br/><br/>A voice calls out to you...<br/><br/>What is your name, travler?")
get input {
player.alias = result
msg ("You have left the mortal coil " + player.alias + ", however, I am willing to send you back.")
ShowMenu ("Were you a man or a woman?", Split ("Male;Female",";"), false) {
player.gender = result
ShowMenu ("Where did you hail from?", Split ("Village;Mountains;Plains;Desert;Forest",";"), false) {
player.home = result
if (player.home = "Village") {
player.species = "human"
} else if (player.home = "Mountains") {
player.species = "???"
} else if (player.home = "Plains") {
player.species = "???"
} else if (player.home = "Desert") {
player.species = "???"
} else if (player.home = "Forest") {
player.species = "???"
}
msg ("So you are " + player.alias + ", the " + player.species + " from the " + player.home + ".")
}
}
}

BlunderingFool
26 Jan 2014, 15:36
It's not a problem. I tried the code and it worked! I'll look to see what's different between the two, thank you very much! ^.=.^

[EDIT]

Oh thank you! I was just tumbling about trying to get things to work too! X.x

For some reason if I type it it never seems to work. Not entirely sure what I'm doing wrong so I'm gonna analyse the differences in code to figure it out.

HegemonKhan
26 Jan 2014, 15:55
it's syntax is complex... it took me a long time to learn how to write it in properly... and I still have a bit of trouble a bit... lol

if you want to try to learn the "rules"...

break it up into these chunks:

" text "
+ Object.Attribute +

(and make sure you have an even number of quote marks, and that they are in their correct locations... both will cause errors if not so)

(make sure you have the pluses separating your texts and your Object.Attributes, and between Object.Attributes and Object.Attributes)

Hopefully this syntax is correct... I haven't done this in awhile... and It may not work (if it doesn't, I do know how to fix it):

msg (game.pov.alias + " is a " + game.pov.age_integer + " year old " + game.pov.age_string + game.pov.gender_string + game.pov.race_string + game.pov.species_string + game.pov.class_string + ".")

game.pov.alias = "HK"
game.pov.age_integer = 18 // (I wish I was 18 again, lol)
game.pov.age_string = "adult"
game.pov.gender_string = "male"
game.pov.race_string = "european"
game.pov.species_string = "human"
game.pov.class_string = "warrior"

output:

HK is a 18 year old adult male european human warrior.

BlunderingFool
26 Jan 2014, 16:02
I think I figured it out, I noticed the problem being that I thought "+ player.X" only had the one +. Every chunk of the statement needs + if I'm not mistaken or stupid. =P

HegemonKhan
26 Jan 2014, 16:17
if this syntax:

msg (game.pov.alias + " is a " + game.pov.age_integer + " year old " + game.pov.age_string + game.pov.gender_string + game.pov.race_string + game.pov.species_string + game.pov.class_string + ".")


doesn't work right (ie: HK is a 18 year old adultmaleeuropeanhumanwarrior.), then this syntax DOES WORK (I know it does):

msg (game.pov.alias + " is a " + game.pov.age_integer + " year old " + game.pov.age_string + " " + game.pov.gender_string + " " + game.pov.race_string + " " + game.pov.species_string + " " + game.pov.class_string + ".")


the chunks:

game.pov.alias +
" is a "
+ game.pov.age_integer +
" year old "
+ game.pov.age_string +
" "
+ game.pov.gender_string +
" "
+ game.pov.race_string +
" "
+ game.pov.species_string +
" "
+ game.pov.class_string +
"."

----------------

P.S.

also, you may want to make (add) your own (a custom) "gender something" String Attribute for your "male~female", as the "gender" attribute is a built-in attribute which deals with the grammer of whether male or female (ie: he, she, or it), and not actually the gender type (male or female) itself.

my own developed coding structure for custom Attributes (for this example~case): "gender_string"

Object (Name): (whatever)
Attribute Name: gender_string
Attribute Type: string
Attribute Value: "male" or "female"

Scripting~Code Syntax: gender_string = "male"
~OR~
Scripting~Code Syntax: gender_string = "female"

Otherwise, you OVERRIDE the built-in "gender" Attribute's function of using the proper grammer (he, she, or it), should you need this in your text sentences.

http://quest5.net/wiki/Gender
http://quest5.net/wiki/Article

---------------

P.S.S.

"game.pov" refers to whoever is your CURRENTLY CONTROLLED Player Object, though if you only have one (and the default, still using its default name of "player"), then "game.pov" and "player", are the same thing.

let me try to explain this somewhat understandably (as I'm not good at clarity)... lol:

(default) Player Object 1: "player"
Player Object 2: "HK"
Player Object 3: "BF" // BF = blunderingfool

you can switch between these 3 Player Characters via in scripting (ie an Object's Verb):

ChangePov (name_of_Player_Object)
http://quest5.net/wiki/ChangePOV

let's say we want to increase the strength of "player":

this obviously works: player.strength = player.strength + 1

and if we're currently controlling "player", this works too: game.pov.strength = game.pov.strength + 1

HOWEVER, if we were currently controlling HK, then "game.pov.strength = game.pov.strength + 1" would incorrectly increase HK's strength, and NOT "player" 's strength.

So, if you got multiple Player Objects, then you got to be careful to use "game.pov" vs "name_of_Player_object" in the correct situations, to get the proper results that you want from it.

BlunderingFool
26 Jan 2014, 17:23
Very informative, thank you. I only plan on having one PC though. =P

Also for some reason it's not moving the player character as it should, keeps leaving them in Village when they should be moved elsewhere. :?

I'm going to try and make it so the player starts in a room called introduction, maybe it's the fact hey're already in Village.
[EDIT]

It didn't work. Can't see anything wrong with the code though.
            msg ("So you are " + player.alias + ", the " + player.species + " from the " + player.home + ".")
msg ("I shall bring you back, however you will be disoriented and weak, you must train and grow to face the comming challanges")
wait {
ClearScreen
if (player.home = Village) {
MoveObject (player, Village)
}
else if (player.home = Mountains) {
MoveObject (player, Mountains)
}
else if (player.home = Plains) {
MoveObject (player, Plains)
}
else if (player.home = Desert) {
MoveObject (player, Desert)
}
else if (player.home = Forest) {
MoveObject (player, Forest)

HegemonKhan
26 Jan 2014, 17:32
In the GUI~Editor:

Run as script -> add a~new script -> Objects -> MoveObject -> (set it up)

http://quest5.net/wiki/MoveObject

In-Code (or within Scripting):

http://quest5.net/wiki/Object
http://quest5.net/wiki/Parent

Object.parent = Name_of_Room_Object

old~original location: player.parent = room

new ("moving to") location: player.parent = room_2

-----------------

useful links for you (as you seem quite capable with working with the code, lol):

1. http://quest5.net/wiki/Category:All_Fun ... t_Commands (page 1, range: A-S)
2. http://quest5.net/w/index.php?title=Cat ... h#mw-pages (page 2, range: S-Z)
3. http://quest5.net/wiki/Object_element
4. http://quest5.net/wiki/Attribute_Types

enjoy :D

HegemonKhan
26 Jan 2014, 17:34
I think you just need the quotes on your location rooms:

MoveObject (player, "Village")
MoveObject (player, "Mountains")
MoveObject (player, "Forest")
etc...

err... Edit~check that, this should fix it (my bad):

if (player.home = "Village") {
-> MoveObject (player, Village)
} else if ....

otherwise... try quotes on both "Village" s code lines:

if (player.home = "Village") {
-> MoveObject (player, "Village")
} else if ....

BlunderingFool
26 Jan 2014, 17:36
Thank you for the links I'll be checking those out.

And I already have the code set up as such. Maybe it's the chaining of if else statements?

[EDIT]
Oh thank you. I'll try that.

[Edit]
Yup, that was the problem. I am just stupid. XD

HegemonKhan
26 Jan 2014, 17:44
it's confusing... you're not stupid...

"Village" = refers to the word (ie: string) of 'Village'

Village = refers to the Object itself of 'Village'

your 'player.home=Village' is set as a String Attribute: player.home="Village" // (the string~word)

so by not having the quotes, you were saying: if (player.home = the OBJECT of 'Village'), whereas you set 'player.home' to the STRING~WORD of "Village"

if "Village" (String) = Village (Object) -> ERROR, because...
(String) = (Object) -> HUH! A String is NOT an Object! -> thus the ERROR

HK crosses his fingers that this makes sense, and isn't confusing blunderingfool further...

so, you want the quotes for the ' if (player.home = "Village") { '

and, you do NOT want the quotes for the ' MoveObject (player, Village) '

--------------

quotes or not, toggles between a word for an Attribute's Value being a Type: String or a Type: Object

BlunderingFool
26 Jan 2014, 17:50
Don't worry I figured it out and got it all working now. :D From here I'm going to link the primary zones with "path" rooms where random encounters and other fun things can happen and flesh out the towns a little too.