Click here to Skip to main content
15,910,009 members
Home / Discussions / C#
   

C#

 
GeneralRe: Looks like C# does not support Global Variables Pin
Brian_TheLion28-Mar-19 16:54
Brian_TheLion28-Mar-19 16:54 
GeneralRe: Looks like C# does not support Global Variables Pin
OriginalGriff29-Mar-19 2:33
mveOriginalGriff29-Mar-19 2:33 
GeneralRe: Looks like C# does not support Global Variables Pin
Brian_TheLion29-Mar-19 3:39
Brian_TheLion29-Mar-19 3:39 
GeneralRe: Looks like C# does not support Global Variables Pin
OriginalGriff1-Apr-19 20:01
mveOriginalGriff1-Apr-19 20:01 
GeneralRe: Looks like C# does not support Global Variables Pin
Brian_TheLion2-Apr-19 1:04
Brian_TheLion2-Apr-19 1:04 
GeneralRe: Looks like C# does not support Global Variables Pin
Brian_TheLion2-Apr-19 14:23
Brian_TheLion2-Apr-19 14:23 
GeneralRe: Looks like C# does not support Global Variables Pin
#realJSOP29-Mar-19 2:28
professional#realJSOP29-Mar-19 2:28 
AnswerRe: Looks like C# does not support Global Variables Pin
OriginalGriff28-Mar-19 0:20
mveOriginalGriff28-Mar-19 0:20 
I've just looked at the Java forum - thanks Richard - and seen what you are trying to do, and I was right: your design is poor.

Why do you need a global variable for "current room", or "inventory"?
Think about it: your player is in a current room, your player has an inventory - and that's true for each player in the game, regardless of whether you have a dozen players or one.
So you make the Location part of each object (including player, swords, bullets, bad guys, whatever - they have a "Location" in the game) and Inventory a part of the player (and probably the bad guy). When you pick something up, it gets added to the objects collection of the inventory of the player. Drop it, and you remove it from the player inventory and added to the room inventory, or the level, or world inventory. Use it, and you remove it from the inventory and discard it.

You pass a Player and possibly a room or level to your methods and they access the items from that.
Global variables aren't needed, and it becomes a whole load easier to add a party of adventurers or whatever to your game instead of a single player.
Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!

GeneralRe: Looks like C# does not support Global Variables Pin
Brian_TheLion28-Mar-19 0:26
Brian_TheLion28-Mar-19 0:26 
GeneralRe: Looks like C# does not support Global Variables Pin
OriginalGriff28-Mar-19 0:40
mveOriginalGriff28-Mar-19 0:40 
GeneralRe: Looks like C# does not support Global Variables Pin
Brian_TheLion28-Mar-19 1:00
Brian_TheLion28-Mar-19 1:00 
GeneralRe: Looks like C# does not support Global Variables Pin
OriginalGriff28-Mar-19 2:35
mveOriginalGriff28-Mar-19 2:35 
QuestionReading Registry Values Pin
ormonds27-Mar-19 15:33
ormonds27-Mar-19 15:33 
AnswerRe: Reading Registry Values Pin
Super Lloyd27-Mar-19 19:38
Super Lloyd27-Mar-19 19:38 
AnswerRe: Reading Registry Values Pin
OriginalGriff27-Mar-19 20:35
mveOriginalGriff27-Mar-19 20:35 
AnswerRe: Reading Registry Values Pin
Luc Pattyn27-Mar-19 22:01
sitebuilderLuc Pattyn27-Mar-19 22:01 
QuestionOData InvalidOperationException. Bad Request - Error in query syntax Pin
Bastien Vandamme26-Mar-19 16:13
Bastien Vandamme26-Mar-19 16:13 
AnswerRe: OData InvalidOperationException. Bad Request - Error in query syntax Pin
Gerry Schmitz26-Mar-19 20:40
mveGerry Schmitz26-Mar-19 20:40 
GeneralRe: OData InvalidOperationException. Bad Request - Error in query syntax Pin
Eddy Vluggen27-Mar-19 3:35
professionalEddy Vluggen27-Mar-19 3:35 
GeneralRe: OData InvalidOperationException. Bad Request - Error in query syntax Pin
Pete O'Hanlon27-Mar-19 3:50
mvePete O'Hanlon27-Mar-19 3:50 
GeneralRe: OData InvalidOperationException. Bad Request - Error in query syntax Pin
Eddy Vluggen27-Mar-19 4:15
professionalEddy Vluggen27-Mar-19 4:15 
GeneralRe: OData InvalidOperationException. Bad Request - Error in query syntax Pin
Richard MacCutchan27-Mar-19 4:33
mveRichard MacCutchan27-Mar-19 4:33 
GeneralRe: OData InvalidOperationException. Bad Request - Error in query syntax Pin
Eddy Vluggen27-Mar-19 4:38
professionalEddy Vluggen27-Mar-19 4:38 
GeneralRe: OData InvalidOperationException. Bad Request - Error in query syntax Pin
Richard MacCutchan27-Mar-19 5:05
mveRichard MacCutchan27-Mar-19 5:05 
GeneralRe: OData InvalidOperationException. Bad Request - Error in query syntax Pin
Eddy Vluggen27-Mar-19 5:31
professionalEddy Vluggen27-Mar-19 5:31 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.