Java-Gaming.org Java4K winners: [ by our judges | by the community ]         
Featured games (67)
games approved by the League of Dukes
Games in Showcase (∞)
games submitted by our members



News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  Print  
  Global variables?  (Read 408 times)
0 Members and 2 Guests are viewing this topic.
Offline SkyAphid

Full Member
**

Posts: 155
Medals: 1



« on: 2012-01-21 11:45:57 »

Is there a way to make variables available to every single class without having to transfer them? It makes things difficult after a while. It's an RPG, so most if ALL methods will use at least one of the characters stats at a point in time.

"God grant me the serenity, to accept the things I cannot change; courage to change the things I can; and wisdom to know the difference."
Offline h3ckboy

JGO Kernel
*****

Posts: 1645
Medals: 4



« Reply #1 on: 2012-01-21 12:21:38 »

Yes, you could make them static. quick google gave this link http://www.roseindia.net/java/beginners/staticvariable.shtml
Offline Roquen

JGO Strike Force
***

Posts: 823
Medals: 25



« Reply #2 on: 2012-01-21 12:27:25 »

I think what's being asked is "globally visible", in which case you make them "public".
Games published by our own members! Go get 'em!
Offline sproingie

JGO Strike Force
***

Posts: 894
Medals: 55



« Reply #3 on: 2012-01-21 12:34:47 »

Making it public is a correct answer -- the right answer however, is that you transfer them.  If you need to transfer a bunch of related state (variables) around at a time, you put them on an object that groups them together, along with the methods that operate on those variables, and you pass the object around.


Offline SkyAphid

Full Member
**

Posts: 155
Medals: 1



« Reply #4 on: 2012-01-21 12:41:06 »

Yes, you could make them static. quick google gave this link http://www.roseindia.net/java/beginners/staticvariable.shtml

Too bad that wasn't the right answer. ;P
Sprongie answered though. Thanks.

"God grant me the serenity, to accept the things I cannot change; courage to change the things I can; and wisdom to know the difference."
Offline h3ckboy

JGO Kernel
*****

Posts: 1645
Medals: 4



« Reply #5 on: 2012-01-22 09:02:13 »

sorry, I misunderstood your question, I thought you meant without having the object.
Pages: [1]
  Print  
 
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!
Page created in 0.1 seconds with 19 queries.