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
Java-Gaming.org
>
Game Development
>
Newbie & Debugging Questions
>
Global variables?
Pages: [
1
]
Print
Global variables?
(Read 408 times)
0 Members and 2 Guests are viewing this topic.
SkyAphid
Full Member
Posts: 155
Medals: 1
Global variables?
«
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."
h3ckboy
JGO Kernel
Posts: 1645
Medals: 4
Re: Global variables?
«
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
Roquen
JGO Strike Force
Posts: 823
Medals: 25
Re: Global variables?
«
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!
sproingie
JGO Strike Force
Posts: 894
Medals: 55
Re: Global variables?
«
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.
SkyAphid
Full Member
Posts: 155
Medals: 1
Re: Global variables?
«
Reply #4 on:
2012-01-21 12:41:06
»
Quote from: h3ckboy 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
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."
h3ckboy
JGO Kernel
Posts: 1645
Medals: 4
Re: Global variables?
«
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:
Please select a destination:
-----------------------------
Games Center
-----------------------------
=> Featured Games
=> Showcase
=> Contests
===> LWJGL16k - 2011
===> 4K Game Competition - 2012
===> JGO Comp Petite
===> Finished Contests
=====> 4K Game Competition - 2011
=====> 4K Game Competition - 2010
=====> 4K Game Competition - 2009
=====> 4K Game Competition - 2008
=====> 4K Game Competition - 2007
=====> 4K Game Competition - 2006
=====> 4K Game Competition - 2005
=====> Tiny Game 2010
=====> JGO Comp 2009
=====> 16K LWJGL Competition - 2005
=====> Java Technology Game Development Contest - 2004
-----------------------------
Discussions
-----------------------------
=> General Discussions
===> Suggestions
=> Business and Project Discussions
===> Jobs and Resumes
===> Community & Volunteer Projects
=> Miscellaneous Topics
-----------------------------
Game Development
-----------------------------
=> Newbie & Debugging Questions
=> Articles & tutorials
=> Game Play & Game Design
=> Game Mechanics
===> Artificial Intelligence
=> Networking & Multiplayer
=> Performance Tuning
=> Shared Code
-----------------------------
Java Game APIs & Engines
-----------------------------
=> Engines, Libraries and Tools
===> Java 3D
===> JInput
===> jMonkeyEngine
===> Xith3D Forums
===> Tools Discussion
=> Java 2D
===> JavaFX
=> OpenGL Development
===> JOGL Development
===> LWJGL Development
=> Java Sound & OpenAL
===> JOAL Development
=> Java on Mobile Devices
===> Android
===> J2ME
Loading...