ArithmeticElement: Operation 'Add' is not defined for types 'Object' and 'Int32'

I'm brand new at this and need some simple help.
I'm following the tutorial for setting up your first game on the online version of Quest, and I ran into an issue.
I'm trying to set a turn script to keep track of the player's turns, but when I run the game after the first time I take a turn, I get this error:

Error running script: Error compiling expression 'player.turns + 1': ArithmeticElement: Operation 'Add' is not defined for types 'Object' and 'Int32'

Can anyone explain to me how to fix this, without having to go in and directly fix the code?


This is a better way to handle that.

IncreaseObjectCounter(player, "turns")

Put that in place of player.turns = player.turns + 1.


I bet player.turns does not exist the first time you are running that script.

Operation 'Add' is not defined for types 'Object' and 'Int32'

Quest cannot find player.turns in the code, so it refers to it as an 'Object' in the error. That error is really trying to say it can't add something that does not exist in the code to a number ('Int32').

Using IncreaseObjectCounter() will create the attribute if it does not exist, hence solving the problem.


Thanks,
I realized I didn't have
set (player, "turn", 0)

This is what I have now,

set (flour, "weight", 500)
set (eggs, "weight", 250)
set (sugar, "weight", 1000)
set (player, "score", 0)
set (player, "turn", 0)
set (player, "statusattributes", NewStringDictionary())
dictionary add (player.statusattributes, "score", "Score: !/10")
dictionary add (player.statusattributes, "turn", "")

With this in the Turn Scripts box below:
player.turns = player.turns + 1

When I try what you said, it still doesn't work.
Any ideas?


Here is the URL of the tutorial I'm using:
http://docs.textadventures.co.uk/quest/tutorial/using_timers_and_turn_scripts.html


Are you doing this online or in the desktop editor?


See if changing that last line to this fixes it:

dictionary add (player.statusattributes, "turn", "Turns: !")

I assume you are putting this code in the start script?


first, creating your 'turns' Integer Attribute (and setting its initial Value of '0'):

'player' Player Object -> 'Attributes' Tab -> Attributes box (bottom box, I think) -> Add -> (see below)

(Object Name: player)
Attribute Name: turns
Attribute Value: 0

and/or (as you can set both of these Attributes up too)

'game' (the special Game-wide Settings and public-publishing info) Object -> 'Attributes' Tab -> Attributes box (bottom box, I think) -> Add -> (see below)

(Object Name: game)
Attribute Name: turns
Attribute Value: 0

or, as/via scripting:

(run as script) -> add new script -> 'variables' category/section -> 'set a variable or attribute' Script -> (see below)

set variable player.turns = [EXPRESSION] 0

and/or (as you can set both of these Attributes up too)

set variable game.turns = [EXPRESSION] 0


** (all of the above) which looks like this in code:**

<object name="player">
  <attr name="turns" type="int">0</attr>
</object>

or

<object name="game">
  <attr name="turns" type="int">0</attr>
</object>

or (both are possible too)

<object name="game">
  <attr name="turns" type="int">0</attr>
</object>

<object name="player">
  <attr name="turns" type="int">0</attr>
</object>

Manipulating/altering/adjusting/changing/re-setting/over-riding/over-writing an Attribute's Value, uses the same scripting:

(run as script) -> add new script -> 'variables' category/section -> 'set a variable or attribute' Script -> (see below)

a simple literal/direct value, example:

set variable player.turns = [EXPRESSION] 100 // it's now '100', instead of being '0'

and/or (as you can set both of these Attributes up too)

set variable game.turns = [EXPRESSION] 100 // it's now '100', instead of being '0'

using a VARIABLE (an 'Attribute' VARIABLE) for its simple value, example:

// set variable player.maximum_life_integer_attribute = [EXPRESSION] 999
set variable player.current_life_integer_attribute = [EXPRESSION] player.maximum_life_integer_attribute
// player.maximum_life_integer_attribute = 999

using complex expressions:

Arithmetic operations:

Addition, simple example: +

set variable player.turns = [expression] player.turns + 1
// like math, you can switch the things in the expression too: set variable player.turns = [expression] 1 + player.turns
// or, example of using a different adder-value: set variable player.turns = [expression] player.turns + 7

Subtraction, simple example: -

set variable player.turns = [expression] player.turns - 1
// note that like math, you can switch things in the expression, but you'll get a different result of course: set variable player.turns = [expression] 1 - player.turns
// or, example of using a different adder-value: set variable player.turns = [expression] player.turns - 4

and the other arithmetic operations/operators (lazy, see code box below):

Multiplication (you get the idea), here's its operator symbol: *

Division (you get the idea), here's its operator symbol: /

Modulus (it's division, but it gets/finds/returns the REMAINDER): %

an example of more complex expression:

// create ("katana") // the in-code syntax for creating an Object, don't know what it is with the GUI/Editor's script options, sorry
// set variable katana.damage_integer_attribute = [EXPRESSION] 50
// set variable player.weapon_object_attribute = [EXPRESSION] katana
// set variable player.strength_integer_attribute = [EXPRESSION] 100

set variable player.damage_integer_attribute = [EXRESSION] player.weapon_object_attribute.damage_integer_attribute + player.weapon_object_attribute.damage_integer_attribute * player.strength_integer_attribute / 100
// player.damage_integer_attribute = (50) + (50) * (100) / 100 = (50) + (50) * 1 = (50) + 50 = 100

vs

// create ("katana") // the in-code syntax for creating an Object, don't know what it is with the GUI/Editor's script options, sorry
// set variable katana.damage_integer_attribute = [EXPRESSION] 50
// set variable player.weapon_object_attribute = [EXPRESSION] katana
// set variable player.strength_integer_attribute = [EXPRESSION] 0

set variable player.damage_integer_attribute = [EXRESSION] player.weapon_object_attribute.damage_integer_attribute + player.weapon_object_attribute.damage_integer_attribute * player.strength_integer_attribute / 100
// player.damage_integer_attribute = (50) + (50) * (0) / 100 = (50) + (50) * 0 = (50) + 0 = 50

vs

// create ("katana") // the in-code syntax for creating an Object, don't know what it is with the GUI/Editor's script options, sorry
// set variable katana.damage_integer_attribute = [EXPRESSION] 50
// set variable player.weapon_object_attribute = [EXPRESSION] katana
// set variable player.strength_integer_attribute = [EXPRESSION] 75

set variable player.damage_integer_attribute = [EXRESSION] player.weapon_object_attribute.damage_integer_attribute + player.weapon_object_attribute.damage_integer_attribute * player.strength_integer_attribute / 100
// player.damage_integer_attribute = (50) + (50) * (75) / 100 = (50) + 1/2 * 75 = (50) + ~37 = ~87

vs

// create ("katana") // the in-code syntax for creating an Object, don't know what it is with the GUI/Editor's script options, sorry
// set variable katana.damage_integer_attribute = [EXPRESSION] 50
// set variable player.weapon_object_attribute = [EXPRESSION] katana
// set variable player.strength_integer_attribute = [EXPRESSION] 25

set variable player.damage_integer_attribute = [EXRESSION] player.weapon_object_attribute.damage_integer_attribute + player.weapon_object_attribute.damage_integer_attribute * player.strength_integer_attribute / 100
// player.damage_integer_attribute = (50) + (50) * (25) / 100 = (50) + 1/2 * 25 = (50) + ~17 = ~67


I'm wondering if you have that in the start script...

I'm also wondering if you have created the flour, eggs, and sugar already.

If you do have that in the start script, and you have also created those three objects, you should see this:

image


Changing that last line of code to what I put in my previous post should give you this:

image


If your objects didn't exist, it would print this:

Error running script: Error compiling expression 'flour': Unknown object or variable 'flour'


I am in the on-line version.


K.V. Yes, I have created the flour, eggs, and sugar already.


Make sure your start script looks just like this:

image


Code View:

image

set (flour, "weight", 500)
set (eggs, "weight", 250)
set (sugar, "weight", 1000)
set (player, "score", 0)
set (player, "turn", 0)
set (player, "statusattributes", NewStringDictionary())
dictionary add (player.statusattributes, "score", "Score: !/10")
dictionary add (player.statusattributes, "turn", "Turns: !")

Also, when going by that tutorial, DO NOT enable the score:

image


Otherwise, you will have the score in the status pane twice:

image


Okay, I have all that:

set (flour, "weight", 500)
set (eggs, "weight", 250)
set (sugar, "weight", 1000)
set (player, "score", 0)
set (player, "turn", 0)
set (player, "statusattributes", NewStringDictionary())
dictionary add (player.statusattributes, "score", "Score: !/10")
dictionary add (player.statusattributes, "turn", "Turns: !")

That only puts "Turns: 0" in the status pane.
It does not increase the count on "Turns: 0" after each turn the player takes.

How do I get it to increase?


How do you post screenshots here?


I post things using imgur.

(Almost) Every time I get

 "Operation 'Add' is not defined for types 'Object' and 'Int32'"

it's because I have an extra space, no space, or someother small typo.

To increase an attribute....

player.hitpoints = 10
player.hitpoints = player.hitpoints + 2

It does not increase the count on "Turns: 0" after each turn the player takes.

How do I get it to increase?

Create a turn script named "turncount". Enable it (IMPORTANT!).

Put this for the script in code view:

if (not GetBoolean(game, "notarealturn")) {
  IncreaseObjectCounter (player, "turn")
}
game.notarealturn = false

If you have any commands which SHOULD NOT cause the turn count to increase (such as HINT), you can add this line to that scrpt's command to keep the turn count from increasing:

game.notarealturn = true

You were using player.turns in one place and player.turn in another.

It doesn't matter which one you use, but you must the same one in every script.


Sorry I didn't catch that sooner.

In your first post, you just posted this error (with no code):

Error running script: Error compiling expression 'player.turns + 1': ArithmeticElement: Operation 'Add' is not defined for types 'Object' and 'Int32'

So, I posted example code using turns, as I assumed you were (and you were, you were just using turn in the script to set the attribute, which is where the problem was; so I guessed correctly at first - player.turns did not exist).


I should have realized what was going on when I saw set (player, "turn") in your second post, but I was attempting to multi-task, so I missed it.


Holy cow! K.V. .... after all this, that's what it was!
It always comes down to something dumb like that doesn't it?

Well, I learned some things along the way, anyhow, so I guess thats ok.

Thanks for the help! :)


This topic is now closed. Topics are closed after 60 days of inactivity.

Support

Forums