This works in my viewDidLoad method. But when I try and call in it in an action called by a button, it acts like it doesn't know what it is. And yeas I did try make pointers via the viewDidLoad method as such:
This works in my viewDidLoad method. But when I try and call in it in an action called by a button, it acts like it doesn't know what it is. And yeas I did try make pointers via the viewDidLoad method as such:
int *variablePointer = &variable;
Pleeease help...
I'm not sure what pointers have to do with this function.
You're calling arc4random in some method and it doesn't work? Or you're trying to access the random number you generated in viewDidLoad, and that doesn't work? It's not clear from your posting.
I'm not sure what pointers have to do with this function.
You're calling arc4random in some method and it doesn't work? Or you're trying to access the random number you generated in viewDidLoad, and that doesn't work? It's not clear from your posting.
joe
I'm sorry, I'm just a bit confused myself lol. I'm trying to access the random value generated in viewDidLoad in an action called by a button.
I'm sorry, I'm just a bit confused myself lol. I'm trying to access the random value generated in viewDidLoad in an action called by a button.
Ok. Is that an instance variable using @property & @synthesize? Or did you try to make it a global variable? And what does the code look like that you're using to access it?
This works in my viewDidLoad method. But when I try and call in it in an action called by a button, it acts like it doesn't know what it is. And yeas I did try make pointers via the viewDidLoad method as such:
int *variablePointer = &variable;
Pleeease help...
I don't think this is a "random" problem, I think it's a problem with variable scope. If you declare a variable inside a method, it can only be used inside that method. If you want it to be used in the whole class, DECLARE it in your .h file, between the brackets of the @interface section. Then you can SET it inside the viewDidLoad method, and read it from anywhere in the class.
If you need to read it from another class, then you need a property (or a method that returns it.)
Code:
//this is a declaration - do this in your .h file
int myVariable;
//this is setting the variable - do this in a method
myVariable = 17;
First, please start a new thread if you have question. Don't post your questions in threads started by others, especially since this one has been dead for two years.
As for your code, there are two problems with: if ([losingVaultNumber = 2])
1. There are no [] brackets around variables. Those are used for sending messages to objects.
2. = is used to assign a value to something, == is used for comparison.
So it should be: if (losingVaultNumber == 2)
Also, it's a better idea to use arc4random() instead of rand(), for various reasons which can be found by Googling.