I want to put money in the game like a bank account the problem is that when I put the variable "BankAccount" which is attached to an Interger in the GameScene or the game view controller only those to know what "account" is. When I go to my secondScene it doesn't know what account is. So. I won't every scene to be able to access/know what "account" is. And if I put account as a variable in all scenes then now they are not the same account. I don't know what to do?
Asked
Active
Viewed 78 times
1 Answers
0
You have to make sure that your variable is outside of any functions or classes, unless you want to use those methods to call the variable.
Variables defined outside of any blocks will be available to the entire application.
If your var is defined inside a block then you need to use that block to call it.
struct getMoney {
var money: Int = 100
}
You could access it like...
var playerMoney = getMoney.money

ALTVisual
- 116
- 10
-
-
1
-
Globals can cause issues when misused. Using appdelegate.swift is another option. See the following link.. [Get Reference from Appdelegate](http://stackoverflow.com/questions/24046164/how-do-i-get-a-reference-to-the-app-delegate-in-swift) – ALTVisual Aug 09 '15 at 06:50