[General Query] Programming languages.

Talk about anything you want, but keep it within the rules, please.
owner123
Super Moderator
Posts: 1943
Joined: February 3rd, 2009, 11:28 pm

Re: [General Query] Programming languages.

Post by owner123 »

If I remember correctly, arrays start at 0, so player[3] is actually 4 players.

If I understand the problem you posted below correctly..
In your pool of random names, when a name is selected, set the value to "" (empty string) and if an empty string is selected you re-roll.

Ex:
playername[0] = "some name 1"
playername[1] = "some name 2"
playername[2] = "some name 2"

Math.Random gets 0.
Now the array looks like this.

playername[0] = ""
playername[1] = "some name 2"
playername[2] = "some name 2"

Math.Random gets 0, and re-rolls and gets something else.

Don't really get your second problem. But use a trigger to set the name of the player, and it remains consistent through the whole game.
Jome
Newcomer
Posts: 3
Joined: November 15th, 2011, 1:02 am

Re: [General Query] Programming languages.

Post by Jome »

Hello, owner123. Thank you for the swift reply.

Not exactly sure if this hits the mark. I'm a bit of confused, but I will try to understand this more. Empty string returns are pretty much even new to me at this junction.

Well, to make it clear, it's like this:

I have a list of 5 names. I have 3 players.
The 5 names are: {John, Tim, Mark, Dick, Harry}

Now, I will create an array of 3 players. Once each player is created, they will pick a name before they enter the game.
Nameless Player 1 gets to pick Dick. Now, I don't want Dick to be selected by Player 2, so he'll choose from the four remaining ones.
Player 2 gets Tim. Now, I don't want Player 3 to be either Tim or Dick. And so on and so on.

This is what's a little complicated. I know there's a solution somewhere down the line, but I'm modifying code to fit what I've learned so far. And so far, I've basically only learned loops, conditions, class calling, and arrays. Basically, the first four chapters of Head First to Java (and some borrowed ideas from Thinking in Java).

As for the second problem, it's actually pretty easy (and simple). I was thinking that as long as the game continues, the players would have to choose names again and again. Moving the block of names from the while() loop eliminates the repetition of finding players.

If anyone would want to check it out, I can e-mail or post the codes for the GuessGame, GameLauncher, and the three Player classes. :/
owner123
Super Moderator
Posts: 1943
Joined: February 3rd, 2009, 11:28 pm

Re: [General Query] Programming languages.

Post by owner123 »

An empty string is basically just nothing. A quote and then an end quote. In wc3edit.net, looks like this.

Code: Select all

 

If Player 1 chooses the name "Dick" (aka the 4th available player name) then you set PlayerNameArray(3) to empty string (aka nothing)
This is because arrays start at 0. So:
PlayerNameArray(0) = "John"
PlayerNameArray(1) = "Tim"
PlayerNameArray(2) = "Mark"
PlayerNameArray(3) = "Dick"
PlayerNameArray(4) = "Harry"

Now in your procedure for choosing names put the condition:
If the name being chosen by the user is equal to an empty string, then ask the user to re-choose.

Empty String on wikipedia: http://en.wikipedia.org/wiki/Empty_stri ... _Languages
Jome
Newcomer
Posts: 3
Joined: November 15th, 2011, 1:02 am

Re: [General Query] Programming languages.

Post by Jome »

Hello, owner123!

Thank you! This one is a bit clearer. Pardon me for not getting it faster. Of course, if the value matches, and if I use an if() block, it has to run again and search for a name. Will try it out right now. I will update in a few hours or so. :)
User avatar
ilovepie
Senior Member
Posts: 102
Joined: June 17th, 2009, 11:31 pm
Title: Assassin

Re: [General Query] Programming languages.

Post by ilovepie »

just go and start doing problems, ex. projecteuler in ANY language. it's better than spending time questioning what is the best.
if you really want to do something practical: http://www.stephenfrasier.com/blog/tech ... xt-decade/

Java is slow but has libraries and is used alot in mobile devices.
User avatar
Dekar
Forum Drunk
Posts: 2893
Joined: January 17th, 2007, 4:22 pm
Location: Darmstadt, Germany
Contact:

Re: [General Query] Programming languages.

Post by Dekar »

I beg to differ, Java isn't slow. (Look at the Jake2 benchmarks for example, a Quake2 port) It eats memory like a small memory eating animal though.
Don't pm me with Warcraft questions, this is a forum so just make a post!

In the world of thinking we are all immigrants. -Robert Nozick
Post Reply