Attribute and Linking with an Item.

metalmario991
In my game I want to have an attribute "Money". I know you create it in the game tab under attirbutes but I still can't figure out how to increase/decrease it without getting an error.
Also I want to have a Money Inventory item. For that, I'd like to know how to get to where when you look at it, the game says "You currently have X dollars" with X being equal to the money attribute. How would I get that to work?

The Pixie
Make sure money is an integer attribute first.

In the relevant script, click Add new script, and select Set a variable or attribute. Set it up like this (to add 10):

Set variable [player.money] = [expression] [player.money+10]

In code, it looks like this:

player.money = player.money+10

To set up yur inventory item, create the item, and put it in the player object. Set it so it cannot be dropped. On the Setup tab, at the bottom, set the "Look at" to text, paste this in:

You have ${player.money} in your wallet.

HegemonKhan
here's a link/guide about using attributes:

viewtopic.php?f=18&t=5559

and near the bottom of the first post of mine in the link above is this, on how to use transactions (such as currency):

(if you want to do more complex stuff, than using Objects is good/neccessary, but for simple stuff, don't use Objects, just use Attributes)

HK wrote:anyways, finally about your question, conceptually about Attribute usage:

you're used to using and thinking in terms of Object (physical thing) usage, but these are very unweildy, such as:

imagine having actual individual 'silver and gold coins' Objects for your currency~transactions, the sheer quantity of them + having to move them around .. YUCK !!!!

INSTEAD, you want to use Attributes!

Your Objects have Attributes, which you can simply adjust, no moving of actual physical things around, nor in having those physical things. Attributes are awesome! see below, using the currency~transactions example (in code):

we're only moving the 'sword' Object around, no 'gold coins' and 'silver coins' extra Objects being moved around

shop_owner.cash = 500
player.cash = 100
sword.price = 50

Buying:

sword.parent = shop_owner

player.cash = player.cash - sword.price
shop_owner.cash = shop_owner.cash + sword.price
sword.parent = player

Selling:

sword.parent = player

player.cash = player.cash + (sword.price / 2)
shop_owner.cash = shop_owner.cash - (sword.price / 2)
sword.parent = shop_owner

*note: this should require 'if' scripting to check if you have enough 'cash' to buy the sword and the shop owner to buy the sword, of course, which I've left out, obviously.

metalmario991
I'm getting the following error for adding or subtracting: Error running script: Error compiling expression 'player.money+ 100': ArithmeticElement: Operation 'Add' is not defined for types 'Object' and 'Int32'
Here's how I set up. Setting it to a set value is fine, but adding and subtracting is not working out.
a1.png

The Pixie
Set player.Money to an integer. Go to the Attribute tab of the player object, and create a new attribute, Money, set it as an integer and give it a value. If it is already there, check the capitalisation.


You do not need to know this, but...

The Quest errors reflect the internal code, rather than Quest script. The message you have says:

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

What this means is that Quest is trying to do addition on null (which it calls an object) and an integer (which it calls an Int32). Your expression is player.money+ 100, so it sees the bit on the left of the add as null, and the bit on the right as an integer. This means player.Money has not been given a starting value.

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

Support

Forums