Constructors.
|
|
Description: I use custom classes and i wanted to send messages to the player from the custom class and not only Client.java. I literally spend a few hours on trying to figure out how to do this (don't laugh its my first time with delta). The solution is simple; had to create a new variable inside PlayerHandler.java and then i could access the client (socket) from within my custom classes.
Step 1:
Open PlayerHandler.java and search forbelow add:Code:client newClient = new client(s, slot);Step 2: Still in PlayerHandler.java add this with your variables:Code:localClient = newClient;Step 3:Code:public static client localClient;
Create a class that you will be using, example:
Step 4: Open client.java and go to line #11618.Code:public class example { client c = PlayerHandler.localClient; public static void sendText() { c.sM("some text"); } }
Step 5: Now you can simply call the sendText method by adding:I hope that this was usefull ^_^Code:example.sendText();




Constructors.
Uh not really, re-initiating client would require a new socket slot.
if that is not your point, i'm already using constructors in my own classes.
Last edited by BinaryX; 06-26-2010 at 08:51 PM. Reason: I ment socket slot lol.




Why would you need a new socket for a Player instance?![]()
I'm not sure, i could have misunderstood the code i seen in the player handler.
Doesn't this represent a new connected client thus creating a new socket slot for it?Code:client newClient = new client(s, slot);

Yep, so the only way to use client in custom classes is via my method, correct?

better way imo would be this
^.^Code:public class EXTENDEDCLASS { public final client c; public EXTENDEDCLASS(client c) { this.c = c; } public void SUPERAWESOME() { c.sM("lol i am teh fkn beast yu noeh?!"); } }
edit: AMG HAXORZ 2K POESTZ!




Sorry dude, but this is actually incredibly disappointing to read.
First of all, how does someone saying "constructors" mean re-instantiating? It's called pointers. Read what silab posted.
Second of all,wat?Code:localClient
I shouldn't even need to explain why that is incredibly stupid.
| « Delta++; Skills Package #1 | [Delta] Adding Drops system like battlescape » |
| Thread Information |
Users Browsing this ThreadThere are currently 1 users browsing this thread. (0 members and 1 guests) |