This week's book giveaway is in the HTML Pages with CSS and JavaScript forum.
We're giving away four copies of React Cookbook: Recipes for Mastering the React Framework and have David Griffiths & Dawn Griffiths on-line!
See this thread for details.
Win a copy of React Cookbook: Recipes for Mastering the React Framework this week in the HTML Pages with CSS and JavaScript forum!

Alex Birmingham

Ranch Hand
+ Follow
since May 22, 2008
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Alex Birmingham

Ah!!! I didn't realize that Java treated numbers as specific primitive types before we assign them variables and therefore cast them.

Now I know why l or L must be added to longs, and f or F to floats.

Much appreciated.
12 years ago
Why do the following two lines of code equate to 0, vs 5.7 or 5?

System.out.println((12 / 21) * 10);

- and -

int = (int) ((12 /21) * 10);
12 years ago
Hey All -

Re-creating a class in my MUD, and looking for stylistic suggestions and general feedback on my code before I convert ~30 legacy children. The class is called ActionEvent, and essentially represents any kind of action - such as an attack - in the game. ActionEvent objects deal with action mechanics (which sometimes contain sub-events, IE component ActionEvents) and narratives.

Here's one child I have converted so far:


...and component class RoundTimeEvent...


PS - Apologies for the screen widening effect, wanted to convey exactly how it's coded. Most sincere thanks in advance!
12 years ago
Hey All -


What is the correct way to find a ServerSocket's IP address? I've tried:
1) getInetAddress() - returns 0.0.0.0/0.0.0.0
1) getLocalSocketAddress() - returns 0.0.0.0/0.0.0.0:4998

The socket is definitely bound, and working locally.


Thanks in advance.
Currently I'm working on a MUD as a hobby. Every 'action' in the game is implemented via abstract class Action and concrete sub-classes, like "Put", "Attack", "ChangeStance", etc.

I'm looking for suggestions on the design. It currently works, and is relatively open for expansion, but it just seems... messy. The architecture is especially messy in regards to sub-classes of Action which deal with Inventory functions.

These Action sub-classes contain three primary components:

- static ActionResult instantiateAction(String input) : This is called using reflection(so it has to be static)on the server, when a client enters a command that corresponds to this Action. The string is entered into another object which returns a Targetable object. If a Targetable object cannot be found, or if the object is not of enum TargetType.ITEM, then an ActionResult is returned with an error, the error is sent to the client(IE: "You can't pick that up, it's a monster!"), and the Action object is not created.

- Constructor(): createNarratives() is called here in order to produce descriptions of the actions, which are in turn sent to clients. The action itself is also placed on the player's actionStack to be performed.

- initMechanics(): This is called when the action is actually performed from a mob's actionStack. As part of these particular sub-classes, an inventory function is called like Stow(Targetable), which can assume that what its getting is an item and isnt null, but not things like whether or not the item is in hand for stowing. Therefore this too returns an ActionResult which is checked for errors. If it has errors, then createNarratives() is called again, and its original (successful) narratives are replaced with an error. (IE: That item is on the ground. Pick it up first.)

Like I said, not the worst architecture in the world, and it works, but we ARE talking about a lot of eggs in one basket: recognition and response to client's text entry, narrative creation and error messaging, and actual nuts and bolts mechanics. (Although the latter is fairly well encapsulated into the Inventory object, this is not the case with most other Action sub-classes. Most of them contain about 25-30 lines of mechanics code. This provides for a TON of customizability in action specifics, but only because the developer is forced to work really low-level at all times.)
12 years ago
Hrmm.... perhaps I posted this in the wrong forum?

Any suggestions on a cross-post welcome.
Currently I'm working on a MUD as a hobby. Every 'action' in the game is implemented via abstract class Action and concrete sub-classes, like "Put", "Attack", "ChangeStance", etc.

I'm looking for suggestions on the design. It currently works, and is relatively open for expansion, but it just seems... messy. The architecture is especially messy in regards to sub-classes of Action which deal with Inventory functions.

These Action sub-classes contain three primary components:

- static ActionResult instantiateAction(String input) : This is called using reflection(so it has to be static)on the server, when a client enters a command that corresponds to this Action. The string is entered into another object which returns a Targetable object. If a Targetable object cannot be found, or if the object is not of enum TargetType.ITEM, then an ActionResult is returned with an error, the error is sent to the client(IE: "You can't pick that up, it's a monster!"), and the Action object is not created.

- Constructor(): createNarratives() is called here in order to produce descriptions of the actions, which are in turn sent to clients. The action itself is also placed on the player's actionStack to be performed.

- initMechanics(): This is called when the action is actually performed from a mob's actionStack. As part of these particular sub-classes, an inventory function is called like Stow(Targetable), which can assume that what its getting is an item and isnt null, but not things like whether or not the item is in hand for stowing. Therefore this too returns an ActionResult which is checked for errors. If it has errors, then createNarratives() is called again, and its original (successful) narratives are replaced with an error. (IE: That item is on the ground. Pick it up first.)

Like I said, not the worst architecture in the world, and it works, but we ARE talking about a lot of eggs in one basket: recognition and response to client's text entry, narrative creation and error messaging, and actual nuts and bolts mechanics. (Although the latter is fairly well encapsulated into the Inventory object, this is not the case with most other Action sub-classes. Most of them contain about 25-30 lines of mechanics code. This provides for a TON of customizability in action specifics, but only because the developer is forced to work really low-level at all times.)
Thanks guys, I feel like that gives me a better understanding of where I need to focus my research (I do indeed use a FileReader.)

Apologies for the obtuse question which belied that I didn't really know what to ask.
12 years ago
Hey all,

After having pretty successfully used what I consider to be some fairly advanced java concepts in my current project, I was distraught to find, after having created a few self-executable JAR's, that my education contained an obvious hole. Allow me to explain...

Some of the objects I use read static text files, which inform the creation of other objects. The problem is that after I JAR my files (which I do using Eclipse, so the process is little more than a click or two), the text files are no longer read correctly. Having researched the issue a bit I have determined that this is probably due to the fact that they cannot be found, due to their CLASSPATH being unknown or incorrect. However, I do not understand what the nature of CLASSPATH is to an extent that I can troubleshoot the issue further.

Additionally, my project originally used RMI as part of the architecture. However I ended up dropping RMI in favor of simple socket input and output streams, at least partly due to more CLASSPATH troubles, this time in respect to stub/skeleton setup.

Any tutorial recommendations on filling in this unfortunate knowledge gap?

Oh, and I fear also that my reliance on Eclipse belies an additional misunderstanding of JAR mechanics...
12 years ago
Problem solved by encapsulating PrintWriter into a thread with a while loop and it's own stack of strings to print (as opposed to a sequential write method which was part of the server's ordinary routine.) Not entirely sure why this solution worked, frankly, because the original problem seemed to have more to do with the operating system's zaney idea about where to end a line.

Nevertheless, it worked.
12 years ago
Can you elaborate a bit, please? Use println where?

If you mean here:



That doesn't do anything different.
12 years ago
Hey guys -

Pretty basic question. I'm using a PrintWriter attached to an OutputStream, with a readLine loop that looks like this:


The BufferedReader and PrintWriter are both attached to to Socket streams. Output loop server-side looks like this:



The problem is that the strings are always cut off at the last \n, with the remainder to be included in the next readLine, which is unabridged save for what lays beyond its own final "\n".

Thoughts?

EDIT: Here's an example of a string that is severed.
"Which profession is your character?\n" +
"Choose from:\n1) Monk\n2) Psionist\n3) Berserker\n4) Mage";

In this case, "\n4)Mage" is transplanted.

EDIT2: So I decided to try and rewrite the whole thing with @n instead of \n, and then build my own code for recognizing @n as \n. Now the entire line, before and after @n, gets transplanted to the next Writer.println(). How does that make sense at all? o.O
[ December 28, 2008: Message edited by: Alex Birmingham ]
12 years ago
Hate to keep this thread alive behind it's natural life, but what about...
a regex represents an article, an adjective, and a noun, and matches either just the (partial or whole) noun, or (partial or whole) adjective + (partial or whole) noun, or article + adjective + noun (all partial or whole).
Here's what I've got after reading the abovementioned tutorial:
^(a.?)?(g(r(e(y.?)?)?)?)?d(o(o(r)?)?)?$

It's 99 percent there, however it doesn't match:
'a gr door'
'a gre door'
or any other string in which grey is partial.

Any hints as to why not? Other parts of speech match partially.
12 years ago
The first regex works, though I added $ so that the user couldn't correctly enter something like marsuphorsecowpie and still get a match.

The second one appears to only respond to 'marsupial.' However, if changed to:
marsu[p]?[pi]?[pia]?[pial]?$
It becomes a lot more functional, but has the issue of matching strings like following:
marsuppipia
marsupipia
marsupiapial

Another option which seems to work identically to the first regex is:
marsu(p|(pi)|(pia)|(pial))?$

EDIT: Oh. And thank you both for responding.

[ December 18, 2008: Message edited by: Alex Birmingham ]
[ December 18, 2008: Message edited by: Alex Birmingham ]
12 years ago