Jump to content
This is not recommended for shared computers
Sign in anonymously
Don't add me to the active users list
FREE SOFTWARE GIVEAWAY
We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.
Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!
16 April 2012 - 11:07 PM
16 April 2012 - 08:37 PM
In C#, any variable with a 'reference type' (i.e. the variable's type is a class or string) could be considered 'handles'.In C#, the code inside a method can 'see':Variables that got passed to the method.Variables that got created in the method.Member variables of the class that contains the method.Public Static (or "global") variables inside any class.There are several possible ways to make your two classes 'share' data:When you 'new' a class, you can pass data via the constructor.If you have a reference to a class, you can assign to any of its public fields or public property setters.If you have a reference to a class, you can call any of its public methods and pass your data as an argument (SiCrane's example).You can make your data 'public static' and then any class can access it directly (try to avoid using this unless you have to).Examples:FormInventory inventory = new FormInventory(player); // Passing it via the constructor.inventory.Player = player; // Using a field/property setter.inventory.SetPlayer(player); // Passing it to a method.var player = Form1.Player; // Accessing it via a global (public static) field/property. (This code would be written in FormInventory's methods)
In C#, any variable with a 'reference type' (i.e. the variable's type is a class or string) could be considered 'handles'.In C#, the code inside a method can 'see':
16 April 2012 - 08:35 PM
16 April 2012 - 08:31 PM
separate this logic from the game code (SQL, XML, Lua, somthing)"
15 April 2012 - 04:50 PM
GameDev.net™, the GameDev.net logo, and GDNet™ are trademarks of GameDev.net, LLC