problem with simple addition (1+1=11)

crownthehunter
29 May 2014, 21:32
Hello, I have been going through the online tutorial on the quest wiki and have got to the part with the turn script. essentially this is just a script that increases by 1 every turn, says something like this :

set variable |player.turns| = |expression| |player.turns + 1| (the lines indicate a box where i have input something. )

when i play the game turns start at 0 then 1 then 11 then 111 then 1111 e.t.c just putting a 1 at the start instead of adding 1. Not a huge problem atm but if i want to make a game with any kind of simple addition the same problem could occur.

R2T1
29 May 2014, 22:22
Without actually seeing your file, check to see that the variable 'player.turns' is an integer (ie. number) and not a string.

HegemonKhan
29 May 2014, 22:31
your adding Strings together, hehe.

Attribute Types:

String = a collection of characters

a
1
dead
abc_123abc_123
fhafhbfebc384ubu3bd39dyy3vy3vdyv_bdjeei7349398du_bjkebuub

so, a String of "1" + a String of "1" = "11"
so, a String of 'a' + a String of 'a' = "aa"
so, a String of "1" + a String of "1" + a String of "1" + a String of "1" + a String of "1" = "11111"

what you got to do is to use Integers (int):

Integer = a number value (-100, -1, 0, 1, 100)

"1" is a String Value (anything in typed into the code with quotes makes it a string)

1 is an Integer Value

A String: "apple"
An Object: apple

see, how 1 can be either an integer or a string?

you got to change your 1's into an Integer Attribute Type

get input {
-> // you type in 1, but when it is used (referenced) in~by the coding, it is: Attribute Type: String, so you got to convert it into: Attribute Type: Integer (int), by doing: ToInt (your_value_be_it_directly_a_number_value_or_a_variable_such_as_'result' )
}

get input {
-> // you type in during game play: 1
-> quest sets its default variable: result = your_input_which_is_a_string
-> variable_x = ToInt (result)
-> // 'ToInt' converts your 'result' from Type:String into Type:Integer, and now 'variable_x' = a type:integer value
}

An Integer: ToInt (result)
A String: ToString (result)

you probably didn't change the attribute type from a string to an integer when you created (added) your attribute in the GUI~Editor:

(whatever) Object -> Attribute (tab) -> Attributes -> Add ->

Object: (whatever)
Attribute Name: blah
Attribute Type: int
Attribute Value: 0

for example (in code):

<game name="blah">
-> // other code (attribute) lines
-> <attr name="turns" type="int">0</attr>
-> // other code (attribute) lines
</game>

<turnscript name="global_turnscript">
-> <enabled />
-> <script>
->-> game.turns = game.turns + 1
-> </script>
</turnscript>

---------

also, you got to make sure both your values being computed (added, subtracted, multiplied, or divided), be integers, as you can't compute a String and Integer, as neither quest~computer nor us-humans understand how to do this, lol.

------

if you provide your game code, we can show you how to change it for it to work, as we don't know your code~script method for generating your number value.

crownthehunter
30 May 2014, 02:51
Ok thank you for the replies I've solved it now, i guess it was kind of obvious it was using the attribute as a string. problem was I had created the attribute and the made it a status attribute and forgot that it was an attribute as well (and that's where the thing is that says string or integer e.t.c).

HegemonKhan
30 May 2014, 02:58
ah, a common new person mistake (I made the same one too, hehe).

remember: 'statusattributes' is only for showing~displaying it on the right side pane during game play

you got to actually add the attribute itself (you can't act upon something that doesn't exist), via 'add attribute', and make sure you change it's type to int (or whatever type you want~need it to be).

--------

having the correct~matching attribute types (and that the actual object or attribute exists) is extremely important in quest (and coding in general, it's universal, as different attribute types are completely different and incompatible things within the coding world), otherwise, you'll get many of the 'infamous' error messages of: ~ 'object32' and 'string32' or 'string32' and 'int32' isn't able to be understood with the operator (">", "<", "=", "+", "-", etc).