player.class issue, please help!
Teabarrel
16 Nov 2017, 21:52Hey, sorry for the apparent urgency in the title, I'm currently under a strict deadline. I'm making a text game from my schools coding art show, and I've come across a real stick in the mud. The game is one about magic, and wanted to create a system in which you could choose a school of magic to cast from. I used a menu to select it and then set that attribute equal to the player.class. Afterwards, I wanted to create a personalized message on the class they chose, yet I am having troubles. Here is an example of the code:
ShowMenu ("Schools: ", Split (" Fire; Frost; Time; Blood; Earth",";"), false) {
player.class = result
if (player.class = "Fire" ) {
PrintCentered (" The Clerk smiles, extending a abnormally warm hand to you. \" A fellow fire student? I was like you once..\" The man is obviously reminiscing, yet about what is unclear. After a few long moments he rises to his feet and with a snap of his fingers, the room around you unfurls like origami to reveal you are somewhere else entirely. ")
} ```
I know that's a bit of a cluster, but I hope it can be deciphered. Essentially I'm using a menu to select it with the showmenu and then setting the player class like I said above, I then tried to use the player's class to define the message but quest is telling me that since they aren't existing variables, I can't do it. Thankyou for any and all responses.
jmnevil54
16 Nov 2017, 22:17If you're using the desktop (computer) version, make player class an attribute. If you're using the online version, either put it in the Game- start script, or tick the "run an Initialization" option in features (I think), and put it there.
You have to set player class to something. Either "" or ! or "!"
player.class = ""
player.class = !
player.class = "!"
Try them all out, see which ones work. If not, just set the player.class to "trainee"
player.class = trainee
mrangel
17 Nov 2017, 00:54You have some extra spaces in the first line of your code. In that case you might be setting class to " Fire"
with a space at the beginning, so the if statement doesn't match.
I'm not sure what you mean by "they aren't existing variables". What's the actual error message you're getting there?
Teabarrel
17 Nov 2017, 01:06I'm getting the following error message :
Error running script: Error compiling expression 'player.class = Earth': Unknown object or variable 'Earth'
in this case I used the earth class but the coding is the same.
Teabarrel
17 Nov 2017, 01:08I've done this but I'm receiving the same message....I am using the desktop version, but I am unfamiliar as how I would format this into an attribute, I'm fairly new to quest.
hegemonkhan
17 Nov 2017, 02:45generally quest is pretty good about handling spaces (white-spaces), but if you want to be completely safe, don't have them, like so:
(make sure you don't have any accidental spaces, along with correct spelling --- quest IS case-sensitive, in your 'if/else-if/cases' too)
// personally, I like this format style for using 'ifs', but you can use the below, if you like it better:
ShowMenu ("Schools: ", Split ("Fire;Frost;Time;Blood;Earth", ";"), false) {
player.class = result
if (player.class = "Fire") {
// blah scripting
} else if (player.class = "Frost") {
// blah scripting
} else if (player.class = "Time") {
// blah scripting
} else if (player.class = "Blood") {
// blah scripting
} else if (player.class = "Earth") {
// blah scripting
}
}
// alternative format style for 'ifs', if you like it better (it allows you to easily check/spot any missing parenthesis):
ShowMenu ("Schools: ", Split ("Fire;Frost;Time;Blood;Earth", ";"), false) {
player.class = result
if (player.class = "Fire") {
// blah scripting
}
else if (player.class = "Frost") {
// blah scripting
}
else if (player.class = "Time") {
// blah scripting
}
else if (player.class = "Blood") {
// blah scripting
}
else if (player.class = "Earth") {
// blah scripting
}
}
// or using the 'switch' Function/Script/Block (it's the exact same as an 'if' Function/Script/Block, but sometimes it's easier/clean to read/look-at and/or just preferred, by some or in various situations, to using it instead of an 'if' Function/Script/Block):
ShowMenu ("Schools: ", Split ("Fire;Frost;Time;Blood;Earth", ";"), false) {
player.class = result
switch (player.class) {
case ("Fire") {
// blah scripting
}
case ("Frost") {
// blah scripting
}
case ("Time") {
// blah scripting
}
case ("Blood") {
// blah scripting
}
case ("Earth") {
// blah scripting
}
}
}
jmnevil54
17 Nov 2017, 03:24To make a showmenu work, you need either an attribute or a list of some kind. And possibly, you have earth put down as "earth" instead of "Earth." And spaces kill the showmenu function.
It should look like this:
ShowMenu ("Schools: ", Split ("Fire;Frost;Time;Blood;Earth",";"), false) {
player.class = result
And I'm confused, do you not know how to make an attribute at all? It's in the attribute tab, I thought.
hegemonkhan
17 Nov 2017, 04:14here's some resources for you:
http://docs.textadventures.co.uk/quest/guides/character_creation.html
http://textadventures.co.uk/forum/samples/topic/5559/attributes-and-if-script-guide-by-hk
ask if you need help with anything
The Pixie
17 Nov 2017, 08:03You have this:
if (player.class = "Fire" ) {
PrintCentered (" ... ")
}
From the error, it sounds like you also have something like this:
if (player.class = Earth ) {
PrintCentered (" .... ")
}
Your error is because Earth
needs to go inside quotes, just as you did with Fire
. Thinking about it, it may be somewhere else entirely, but the problem is the somewhere Earth
needs to go inside quotes.
ETA: Also, as others have said, remove the spaces from the list of schools.