Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 233 234 [235] 236 237 ... 796

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

Dutchling

  • Bay Watcher
  • Ridin' with Biden
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3510 on: November 17, 2012, 02:52:05 pm »

Allow for only one button press per frame/turn/cycle/whatever?
Logged

GreatJustice

  • Bay Watcher
  • ☭The adventure continues (refresh)☭
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3511 on: November 17, 2012, 03:19:31 pm »

Well, the real problem isn't that players mash the buttons, its that the "simple" music trigger can't work. For example, I say "if x is pushed, stop songs abc, play song d", it crashes because a, b and c weren't playing in the first place. The only solution I've found is to make booleans that check every possibility ("If a is playing and player hits x, stop a and play x" etc), but I'd vastly prefer something shorter.
Logged
The person supporting regenerating health, when asked why you can see when shot in the eye justified it as 'you put on an eyepatch'. When asked what happens when you are then shot in the other eye, he said that you put an eyepatch on that eye. When asked how you'd be able to see, he said that your first eye would have healed by then.

Professional Bridge Toll Collector?

Putnam

  • Bay Watcher
  • DAT WIZARD
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3512 on: November 17, 2012, 03:28:02 pm »

Have a boolean that switches to true when music is on and switches to 0 when it's off and only have it stop the other if they pass a boolean check that checks if that particular one is on?

GreatJustice

  • Bay Watcher
  • ☭The adventure continues (refresh)☭
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3513 on: November 17, 2012, 03:37:20 pm »

Yeah, that's the present setup. However, it takes ~16 blocks of code to just set up the switch, never mind changing the victory conditions (since I need to stop each song separately).
Logged
The person supporting regenerating health, when asked why you can see when shot in the eye justified it as 'you put on an eyepatch'. When asked what happens when you are then shot in the other eye, he said that you put an eyepatch on that eye. When asked how you'd be able to see, he said that your first eye would have healed by then.

Professional Bridge Toll Collector?

Nadaka

  • Bay Watcher
    • View Profile
    • http://www.nadaka.us
Re: if self.isCoder(): post() #Programming Thread
« Reply #3514 on: November 17, 2012, 03:38:54 pm »

Yeah, that's the present setup. However, it takes ~16 blocks of code to just set up the switch, never mind changing the victory conditions (since I need to stop each song separately).
or instead of a giant set of blocks you could have a list of music and loop through it to turn them off.
Logged
Take me out to the black, tell them I ain't comin' back...
I don't care cause I'm still free, you can't take the sky from me...

I turned myself into a monster, to fight against the monsters of the world.

alway

  • Bay Watcher
  • 🏳️‍⚧️
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3515 on: November 17, 2012, 07:03:48 pm »

Yeah, when you find yourself in a situation in which you are writing tons of code to do something conceptually very simple, there is one question you need to ask yourself: "Can I do this a better way?" Spoiler alert: the answer is pretty much always "Yes."

In cases like this one, arrays and for loops are your friends. Essentially, if you think about the problem as if you were working with 10 million cases instead of 10, you will probably realize better ways of doing it.
Code: [Select]
bool active[NUMSONGS];
Song songs[NUMSONGS];

void Input(int button)
{
    StopAll();
    PlaySong(button);
}

void StopAll()
{
   for(int i=0; i<NUMSONGS; i++)
   {
       if(active[i])
       {
           songs[i].Stop();
           active[i] = false;
       }
   }
}

void PlaySong(int button)
{
     if(button > -1 && button < NUMSONGS)
     {
         songs[button].Play();
         active[button] = true;
     }
}
Logged

Twiggie

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3516 on: November 17, 2012, 07:09:05 pm »

isnt it better practice to just have one array of an object that wraps a boolean and a song?
Logged

alway

  • Bay Watcher
  • 🏳️‍⚧️
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3517 on: November 17, 2012, 07:17:07 pm »

Yeah, that too.
Logged

Twiggie

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3518 on: November 17, 2012, 11:15:22 pm »

Actually thinking about that helped me out in my current project. Basically I have a whole bunch of methods that have the same signature (excepting names), which i needed to loop through, but I'm working in java so I can't use function pointers. Anyway this led me to this post, which let me cut down a lot of lines in a couple of commonly-used methods. Apparently this is the command design pattern.
Logged

Mego

  • Bay Watcher
  • [PREFSTRING:MADNESS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3519 on: November 17, 2012, 11:26:03 pm »

but I'm working in java so I can't use function pointers.

Well... That isn't entirely true. There's two ways you can emulate the functionality of function pointers in Java. The first is using interfaces. The second is using the Method class. Both are painful.

Twiggie

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3520 on: November 17, 2012, 11:34:29 pm »

yeah thats what i meant, im using an interface now.
Logged

Max White

  • Bay Watcher
  • Still not hollowed!
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3521 on: November 19, 2012, 03:40:54 am »

Progress has been great on something I started today. I just feel the need to share.
Spoiler (click to show/hide)
Screen is resizable, camera follows your player around, not multiplayer yet but ready for that to be set up, overworld ready to change based on events. All in pretty much no time at all. Oh, and the guy walks properly.

GalenEvil

  • Bay Watcher
    • View Profile
    • Mac-Man Games
Re: if self.isCoder(): post() #Programming Thread
« Reply #3522 on: November 19, 2012, 07:36:57 am »

Made a prototype chat client to go with my first paid gig as a professional programmer ^_^ It is pretty low functionality currently but you can create new chat-tabs and destroy all of them except for the "Main" tab which is persistent.
Click here to chat!...With yourself!

Also did some more fun stuff with 3D Simplex Noise :) very interesting actually. Will not post picture unless asked though, since it's like 1.25MB and already posted it into the "Random Things you made" thread :P

Will post my attempt at voxelized lighting though!

Still needs some work but it's getting there!
Logged
Fun is Fun......Done is Done... or is that Done is !!FUN!!?
Quote from: Mr Frog
Digging's a lot like surgery, see -- you grab the sharp thing and then drive the sharp end of the sharp thing in as hard as you can and then stuff goes flying and then stuff falls out and then there's a big hole and you're done. I kinda wish there was more screaming, but rocks don't hurt so I guess it can't be helped.

MagmaMcFry

  • Bay Watcher
  • [EXISTS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3523 on: November 19, 2012, 07:41:21 am »

Will post my attempt at voxelized lighting though!
Spoiler (click to show/hide)
Still needs some work but it's getting there!

Looks like you made the solid blocks have light levels (instead of the air blocks). May I ask why?
Logged

GalenEvil

  • Bay Watcher
    • View Profile
    • Mac-Man Games
Re: if self.isCoder(): post() #Programming Thread
« Reply #3524 on: November 19, 2012, 08:01:20 am »

No, the air blocks contain the light levels. They just aren't passing the lighting information in a good way onto the surrounding surfaces. Right now it is just face lighting instead of vertex lighting so it isn't very smooth. Also, the air blocks get lighting if they are even marginally passed through by my voxel-ray-things so it's not very good quality either.
Logged
Fun is Fun......Done is Done... or is that Done is !!FUN!!?
Quote from: Mr Frog
Digging's a lot like surgery, see -- you grab the sharp thing and then drive the sharp end of the sharp thing in as hard as you can and then stuff goes flying and then stuff falls out and then there's a big hole and you're done. I kinda wish there was more screaming, but rocks don't hurt so I guess it can't be helped.
Pages: 1 ... 233 234 [235] 236 237 ... 796