How to add to and call value of an integer?

It's pretty straightforward this time. I made an integer attribute in an object. The variable is supposed to increase each turn you use one of the verbs of the object. After ten turn counts, the player is meant to move to a different room.
So how would I do a code that would add 1 to the integer when run, and how do I do an if statement on how current value of the integer to know when it has turned ten to move the player object?


Just create a function, say INCREMENT and call it from within the script of each verb. Inside INCREMENT, add 1 to your integer attribute and when = 10 move the player to the required room.


Thanks, that is a big help, but I still need to know how to call the value of a variable like an integer and add to it in code. I figure it's very simple but I could not find the answer on google.


object.attribute = object.attribute + 1
If object.attribute = 10 move player


That's exactly what I am looking for. Thank you, so much.


Just one last question. Is there a way in code to have the if statement asking if the integer is equal to ten, instead be greater than nine?


Just one last question. Is there a way in code to have the if statement asking if the integer is equal to ten, instead be greater than nine?

You would probably learn a lot of these answers if you did the tutorials.
But, in this case, there are a 6 operators which compare two numeric values:

  • = - equal to
  • > - greater than
  • >= - greater than or equal to
  • < - less than
  • <= - less than or equal to
  • <> - different to

For the case where you want an attribute to be greater than nine, you could use any of these:

if (objectname.attributename > 9) {
if (objectname.attributename >= 10) {
if (not objectname.attributename <= 9) {
if (not objectname.attributename < 10) {

or even …

if (9 < objectname.attributename) {
if (10 <= objectname.attributename) {
if (not 9 >= objectname.attributename) {
if (not 10 > objectname.attributename) {

Note that = and <> will work on most types of attribute, as long as they are the same type. So you can use them to compare two numeric types, two strings, or two objects.

The other four only work on numbers, and will cause an error if the attribute isn't numeric.


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

Support

Forums