Trouble with setting variables.
IMainLeeSin
13 Jul 2016, 09:53Hello everyone. So I've been working on character creation for a game project of mine and I'm just stumped on what my problem is.
So I did the basics - name, gender, et cetera. Now I'm going to set a series of variables that determine the characters stats (Strength, defense, et cetera.) I don't even want to try and make something as complicated as a separate window where you can distribute points or anything, so I go with the idea of essentially using a class system to determine beginning stats.
So I have the game show a menu with four options. The game then sets player.class to the result of the menu. The script then checks what player.class is, and if it's equal to a certain class then it changes the variables to the appropriate number.
The problem I'm having is even though I'm setting player.class to the result of the menu, the game complains that said result isn't a "object or variable."
Here's the code snippet:
ShowMenu ("You were a", Split ("Soldier;Scholar;Thief;Gambler",";"), false) {
player.class = result
if (player.class = Soldier) {
str = GetRandomInt(5,10)
def = GetRandomInt(3,8)
agl = GetRandomInt(1,5)
int = GetRandomInt(1,5)
cha = GetRandomInt(2,5)
luck = GetRandomInt(1,10)
}
if (player.class = Scholar) {
str = GetRandomInt(1,5)
def = GetRandomInt(2,5)
agl = GetRandomInt(3,8)
int = GetRandomInt(5,10)
cha = GetRandomInt(1,5)
luck = GetRandomInt(1,10)
}
if (player.class = Thief) {
str = GetRandomInt(1,5)
def = GetRandomInt(1,5)
agl = GetRandomInt(5,10)
int = GetRandomInt(2,5)
cha = GetRandomInt(3,8)
luck = GetRandomInt(1,10)
}
if (player.class = Gambler) {
str = GetRandomInt(1,15)
def = GetRandomInt(1,15)
agl = GetRandomInt(1,15)
int = GetRandomInt(1,15)
cha = GetRandomInt(1,15)
luck = GetRandomInt(1,20)
}
}
bergedorfcacher
13 Jul 2016, 10:27I assume player.class is a string attribute. If so, you need to change your expressions like this: if (player.class = "Soldier").
bergedorfcacher
13 Jul 2016, 10:29Just read your text again, probably my previous post was beside the point. But anyway: result is a string, so if player.class is NOT a string attribute, that is your problem.
hegemonkhan
13 Jul 2016, 12:56ShowMenu ("You were a ", Split ("Soldier;Scholar;Thief;Gambler",";"), false) {
player.class = result
if (player.class = "Soldier") {
player.str = GetRandomInt(5,10)
player.def = GetRandomInt(3,8)
player.agl = GetRandomInt(1,5)
player.int = GetRandomInt(1,5)
player.cha = GetRandomInt(2,5)
player.luck = GetRandomInt(1,10)
}
else if (player.class = "Scholar") {
player.str = GetRandomInt(1,5)
player.def = GetRandomInt(2,5)
player.agl = GetRandomInt(3,8)
player.int = GetRandomInt(5,10)
player.cha = GetRandomInt(1,5)
player.luck = GetRandomInt(1,10)
}
else if (player.class = Thief) {
player.str = GetRandomInt(1,5)
player.def = GetRandomInt(1,5)
player.agl = GetRandomInt(5,10)
player.int = GetRandomInt(2,5)
player.cha = GetRandomInt(3,8)
player.luck = GetRandomInt(1,10)
}
else if (player.class = Gambler) {
player.str = GetRandomInt(1,15)
player.def = GetRandomInt(1,15)
player.agl = GetRandomInt(1,15)
player.int = GetRandomInt(1,15)
player.cha = GetRandomInt(1,15)
player.luck = GetRandomInt(1,20)
}
}
see these links if you want more in depth explanation/help:
http://docs.textadventures.co.uk/quest/guides/
http://docs.textadventures.co.uk/quest/guides/character_creation.html
http://textadventures.co.uk/forum/samples
http://textadventures.co.uk/forum/samples/topic/5559/attributes-and-if-script-guide-by-hk
http://textadventures.co.uk/forum/quest/topic/5387/i-really-need-help (if you want to display, via through the built-in 'statusattributes' StringDictionary Attribute ONLY for the 'game' Game Object and the Player Objects such as the default 'player' Player Object, the Attributes in the pane on the right during game play)
you need the double quotes surrounding/encasing your classes (="Solder", ="Scholar", ="Thief", ="Gambler"), as they're (likely) Strings (I doubt you created your Classes as Objects --- if you did, then you do NOT encase them in double quotes, as almost anything not in double quotes is recognized as an Object by the quest program), and anything within double quotes is understood as a String by the quest program.
conceptual explanation:
// let's say you selected: player.class = "soldier" // (player.class <=== result <=== your menu selected choice: "Soldier")
if (player.class = "Soldier") { /* scripting */ }
// if (player.class: "Soldier" = "Soldier") {
// if ("Soldier" = "Soldier") // ding ding ding -> TRUE -> then do its scripting
// let's say you selected: player.class = "Gambler" // (player.class <=== result <=== your menu selected choice: "Gambler")
if (player.class = "Soldier") { /* scripting */ }
// if (player.class: "Gambler" = "Soldier") {
// if ("Gambler" = "Soldier") // bzz -> FALSE -> thus, quest tries the next (else if) condition (see below)
else if (player.class = "Scholar") { /* scripting */ }
// else if (player.class: "Gambler" = "Scholar") {
// else if ("Gambler" = "Scholar") // bzz -> FALSE -> thus, quest tries the next (else if) condition (see below)
else if (player.class = "Thief") { /* scripting */ }
// else if (player.class: "Gambler" = "Thief") {
// else if ("Gambler" = "Thief") // bzz -> FALSE -> thus, quest tries the next (else if) condition (see below)
else if (player.class = "Gambler") { /* scripting */ }
// else if (player.class: "Gambler" = "Gambler") {
// else if ("Gambler" = "Gambler") // ding ding ding -> TRUE -> then do its scripting
the reason you want to do the 'else ifs' (a single scripting block: if~else ifs) vs 'ifs' (multiple scripting blocks):
if (player.class = "Soldier") { /* scripting / }
if (player.class = "Scholar") { / scripting / }
if (player.class = "Thief") { / scripting / }
if (player.class = "Gambler") { / scripting */ }
even if your chosen 'player.class=Soldier', after it does its scripting, it'll still no matter what, also check if your 'player.class=Soldier' equals: "Scholar", "Thief", and "Gambler". We do NOT want it to be doing these extra (COMPLETELY UN-NEEDED) actions! This is because each 'if' is (a) separate (scripting block) from each other.
whereas:
if (player.class = "Soldier") { /* scripting / }
else if (player.class = "Scholar") { / scripting / }
else if (player.class = "Thief") { / scripting / }
else if (player.class = "Gambler") { / scripting */ }
is a SINGLE SCRIPTING BLOCK: the 'else if (player.class = "Scholar")' will ONLY be done if it fails the 'if (player.class = "Soldier", the 'else if (player.class = "Thief")' will ONLY be done if it fails the 'else if (player.class = "Scholar")', and the 'else if (player.class = "Gambler")' will only be done if it fails the 'else if (player.class = "Thief").
here's the 4 different combinations of scripting blocks for the 'if~else if~else' Script:
if (VARIABLE = VALUE) { /* scripting */ }
if (VARIABLE = VALUE) { /* scripting */ }
else { /* scripting */ }
if (VARIABLE = VALUE) { /* scripting */ }
else if (VARIABLE = VALUE_2) { /* scripting */ }
// etc 'else ifs' as you need/want
if (VARIABLE = VALUE) { /* scripting */ }
else if (VARIABLE = VALUE_2) { /* scripting */ }
// etc 'else ifs' as you need/want
else { /* scripting */ }
VARIABLES (3 types --- keeping this simple):
- Variables: example: strength = 100
- Attributes: example: player.strength = 100
- Arguments/Parameters (this deals with Functions, Commands, Delegates, and whatever else)
for the most part, you should be using Attributes and not Variables, because by having the Object contain your Attribute VARIABLE (in code: via using the dot-period connector-attacher, in GUI~Editor via non-scripting: 'whatever' Object -> 'Attributes' Tab -> Attributes -> Add -> set it up, in GUI~Editor via scripting: 'whatever' Element -> run as script -> add new script -> 'variables' section/category -> 'set a variable or attribute' Script -> [EXPRESSION] -> set variable OBJECT_NAME.ATTRIBUTE_NAME = [EXPRESSION] VALUE), you're essentially 'saving' that Attribute (and thus its Value --- so long as the Object exists and/or still exists, lol), allowing you to "load" (use/re-use) the Attribute (OBJECT_NAME.ATTRIBUTE_NAME) anywhere in your game that you want and as much as you want. Attributes are 'global' VARIABLES
Variables, on the other hand, only work for that scripting you use them in, as once the scripting is done, they're erased. They're NOT preserved/saved for 'loading'/use/re-use elsewhere in your game. Variables are 'local' VARIABLES.
IMainLeeSin
13 Jul 2016, 22:39Thank you everyone! I just couldn't figure out why it needed my classes to be objects. I've got it fixed now and everything looks nice.
IMainLeeSin
14 Jul 2016, 20:23Hey so small question I can't figure out. So in my status bar I want to display the characters health attribute. That's simple enough, but I want the health attribute to = str + def, and when I set the hp attribute to anything other than an integer or a string the status attributes stops displaying it. I'm unsure how I would go about having it display this.
hegemonkhan
14 Jul 2016, 21:16use this link as a guide:
http://textadventures.co.uk/forum/quest/topic/5387/i-really-need-help
if you still need help and/or don't understand anything, ask.
basically, you need:
'player.str' to be an Integer Attribute
'player.def' to be an Integer Attribute
'player.health' to be an Integer Attribute
in/for your special 'changed' Script Attribute:
('player' Player Object -> 'Attributes' Tab -> Attributes -> Add -> 'set a variable or attribute' Script)
(Object Name: player)
Attribute Name: changedstr
Attribute Type: script
Attribute Value: (see below)
run as script -> add new script -> 'variables' category/section -> 'set a variable or attribute' Script -> [EXPRESSION] -> (see below)
set variable player.health = [EXPRESSION] player.str + player.def
('player' Player Object -> 'Attributes' Tab -> Attributes -> Add -> 'set a variable or attribute' Script)
(Object Name: player)
Attribute Name: changeddef
Attribute Type: script
Attribute Value: (see below)
run as script -> add new script -> 'variables' category/section -> 'set a variable or attribute' Script -> [EXPRESSION] -> (see below)
set variable player.health = [EXPRESSION] player.str + player.def
and for your 'statusattributes' String Dictionary Attribute (this displays your Attributes during game play in the pane on the right):
'player' Player Object -> 'Attributes' Tab -> Status Attributes -> Add -> (see below)
Attribute Name: health
Attribute Field: Health: ! // this displays (for example): Health: 999 // or if you rather, do this: ! Health // which would display (for example): 999 Health
you need the special 'changed' Script Attribute, as the 'statusattributes' displayment doesn't update the displayment of its Attributes' Values, but the 'changed' Script causes this effect, so your 'statusattributes' should display the up-to-date/current/correct Values