Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 608 609 [610] 611 612 ... 796

Author Topic: if self.isCoder(): post() #Programming Thread  (Read 902834 times)

nogoodnames

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9135 on: February 27, 2016, 02:11:58 am »

It looks like you managed to combine two lines of code. Judging by the comment, this line:
Code: [Select]
JOptionPane.showMessageDialog(null, bankAccounts.newBankAccount(i).getAccountId() + getPassword());//DISPLAY MESSEGE OF CREATION
...should be outside the for loop and should read like this:
Code: [Select]
JOptionPane.showMessageDialog(null, newBankAccount().getAccountId() + newBankAccount.getPassword());//DISPLAY MESSEGE OF CREATION
That should access the details of the newly created account.

Inside the for loop, if you want to have it display the details of every account in the array, it should look like this:
Code: [Select]
JOptionPane.showMessageDialog(null, bankAccounts[i].getAccountId() + bankAccounts[i].getPassword());
That will access the account at index i and display the information.

Disclaimer: I have never really used Java, but I assume it's using the same syntax as every other C-based language.
Logged
Life is, in a word, volcanoes.
                        - Random human lord

DragonDePlatino

  • Bay Watcher
  • [HABIT:COLLECT_WEALTH]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9136 on: February 27, 2016, 11:03:48 am »

Having a hard time wrapping my head around this one. In C++, what is the most concise statement that passes if *only one* of my conditions is true?
Code: [Select]
bool x = false;
bool y = true;
bool z = true;

if(only x, only y or only z)
{
do stuff;
}

If I try (x || y || z), my statement continues at y and ignores z. I think I could do this with a monstrous nested if statement (I have way more bools) but I'd like to know if there's a better way before I attempt that.

EDIT:

Silly me! I should just try if(x + y + z == 1). Never mind.
« Last Edit: February 27, 2016, 11:43:28 am by DragonDePlatino »
Logged

Mephisto

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9137 on: February 27, 2016, 11:45:46 am »

Having a hard time wrapping my head around this one. In C++, what is the most concise statement that passes if *only one* of my conditions is true?
Code: [Select]
bool x = false;
bool y = true;
bool z = true;

if(only x, only y or only z)
{
do stuff;
}

If I try (x || y || z), my statement continues at y and ignores z. I think I could do this with a monstrous nested if statement (I have way more bools) but I'd like to know if there's a better way before I attempt that.

EDIT:

Silly me! I should just try if(x + y + z == 1). Never mind.

Sounds like an XOR. x^y^z
Logged

scrdest

  • Bay Watcher
  • Girlcat?/o_ o
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9138 on: February 27, 2016, 12:30:07 pm »

I'm building an actions tree for an action planner AI in a C++-esque language. It gets a goal on start, loops through actions that have an effect matching the goal, and checks requirements for these actions.

If they are not met already it goes through the same process for a subbranch with meeting the requirement as a goal, if it is the path is considered a valid path, and once all paths are found, it uses A* to find an optimal plan of actions.

Now, I've got the tree-building pretty much done, but I need advice how to access the branches when the paths are all set up.

Right now, I have a variable incremented on each iteration of the loop that doubles as a pointer to the list position of the action, in other words if we have three total possible actions A, B, C they are being pointed to as 1, 2, 3; if you need to do B to be able to do A, it looks at all the possible actions, once again the same ABC, and among them finds a valid path in the action B, making it 1.2, if B needs C to be done to work - 1.2.3 and so on.

I'm not sure how to put that together that way, though, and I wonder if there's a better way to access these.
Logged
We are doomed. It's just that whatever is going to kill us all just happens to be, from a scientific standpoint, pretty frickin' awesome.

Bauglir

  • Bay Watcher
  • Let us make Good
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9139 on: February 27, 2016, 01:13:20 pm »

Sounds like an XOR. x^y^z
This will run any time an odd number of conditions are true, so it doesn't quite work.
Logged
In the days when Sussman was a novice, Minsky once came to him as he sat hacking at the PDP-6.
“What are you doing?”, asked Minsky. “I am training a randomly wired neural net to play Tic-Tac-Toe” Sussman replied. “Why is the net wired randomly?”, asked Minsky. “I do not want it to have any preconceptions of how to play”, Sussman said.
Minsky then shut his eyes. “Why do you close your eyes?”, Sussman asked his teacher.
“So that the room will be empty.”
At that moment, Sussman was enlightened.

TheBiggerFish

  • Bay Watcher
  • Somewhere around here.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9140 on: February 27, 2016, 01:16:40 pm »

((x^y)^z)^a...?
Logged
Sigtext

It has been determined that Trump is an average unladen swallow travelling northbound at his maximum sustainable speed of -3 Obama-cubits per second in the middle of a class 3 hurricane.

DragonDePlatino

  • Bay Watcher
  • [HABIT:COLLECT_WEALTH]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9141 on: February 27, 2016, 02:13:32 pm »

Thanks for the help, but I'll be sticking to if(x + y + z == 1).

For context, I'm checking if only one of 8 directional keys has been hit before I handle input in my game. (x NAND y) AND (x NAND z) AND (y NAND z) works, but becomes incredibly complicated when testing 8 booleans against each other. x^y^z worked, but had that odd-numbered problem.

MagmaMcFry

  • Bay Watcher
  • [EXISTS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9142 on: February 27, 2016, 02:16:49 pm »

Sounds like there is a better way to do this though. What are these 8 keys controlling?
Logged

TheBiggerFish

  • Bay Watcher
  • Somewhere around here.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9143 on: February 27, 2016, 02:47:33 pm »

Would ((x XOR y) XOR z) XOR a...
Work though?
Purely curiosity at this point...
« Last Edit: February 27, 2016, 02:49:38 pm by TheBiggerFish »
Logged
Sigtext

It has been determined that Trump is an average unladen swallow travelling northbound at his maximum sustainable speed of -3 Obama-cubits per second in the middle of a class 3 hurricane.

3man75

  • Bay Watcher
  • I will fire this rocket
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9144 on: February 27, 2016, 03:14:27 pm »

Spoiler (click to show/hide)

Can someone help me make this password work? I"m trying to make a 4 letter password fit into my constructors. I thought I had it working but no.
Logged

DragonDePlatino

  • Bay Watcher
  • [HABIT:COLLECT_WEALTH]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9145 on: February 27, 2016, 04:10:31 pm »

Sounds like there is a better way to do this though. What are these 8 keys controlling?

For my first game (and first C++ program, really) I'm making a roguelike. Like most roguelikes, each directional key corresponds to an x and y direction, like so:

Spoiler (click to show/hide)
                           
I then take in inputs and match each key to a direction:

Spoiler (click to show/hide)
   
Originally, I had a big string of if-else statements for each button but this is much shorter. I think I've sacrificed some of my readability, though.
« Last Edit: February 27, 2016, 04:16:06 pm by DragonDePlatino »
Logged

Putnam

  • Bay Watcher
  • DAT WIZARD
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9146 on: February 27, 2016, 04:52:40 pm »

Switch statement?

Orange Wizard

  • Bay Watcher
  • mou ii yo
    • View Profile
    • S M U G
Re: if self.isCoder(): post() #Programming Thread
« Reply #9147 on: February 27, 2016, 06:39:55 pm »

I used a python dictionary of {keycode:command} that actually worked pretty well but I ditched it because a huge string of if::else statements requires less thinking, and I'm not very good at thinking.
Logged
Please don't shitpost, it lowers the quality of discourse
Hard science is like a sword, and soft science is like fear. You can use both to equally powerful results, but even if your opponent disbelieve your stabs, they will still die.

MagmaMcFry

  • Bay Watcher
  • [EXISTS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9148 on: February 27, 2016, 06:52:42 pm »

<roguelike>
If your roguelike is turn-based, I suggest using the keypress events instead of checking for down-ness. If your roguelike is realtime, then why not just find the first pressed key and use that?
Logged

EnigmaticHat

  • Bay Watcher
  • I vibrate, I die, I vibrate again
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9149 on: February 27, 2016, 07:41:05 pm »

<roguelike>
If your roguelike is turn-based, I suggest using the keypress events instead of checking for down-ness. If your roguelike is realtime, then why not just find the first pressed key and use that?
Its safer in games to check for a switch from down > up status, unless your game specifically requires the ability to hold down buttons.  Negates the impact of accidental button presses and allows people to reconsider their actions, which is especially important in roguelikes.  Also prevents those glitches where the game thinks a button is being held down when its not.
Logged
"T-take this non-euclidean geometry, h-humanity-baka. I m-made it, but not because I l-li-l-like you or anything! I just felt s-sorry for you, b-baka."
You misspelled seance.  Are possessing Draignean?  Are you actually a ghost in the shell? You have to tell us if you are, that's the rule
Pages: 1 ... 608 609 [610] 611 612 ... 796