The Dink Network

wait_for_button

April 30th 2014, 05:47 PM
dragon.gif
Quiztis
Peasant He/Him Sweden bloop
Life? What's that? Can I download it?! 
Why can't I use all the buttons for wait_for_button? Like &result == 68 for D? Seems like only the standard buttons for Dink apply like CTRL, ESC, SPACE, arrow keys etc.

void main(void)
{
freeze(1);
loop:
wait_for_button();

if (&result == 68)
{
say("ass",1);
}

if (&result == 5)
{
say("ass",1);
}

goto loop;
}

Main problem: Dink will say ass when I press ESC, but not when I press D.
April 30th 2014, 05:47 PM
wizardg.gif
Is this post incomplete?

nevermind.
April 30th 2014, 05:48 PM
dragon.gif
Quiztis
Peasant He/Him Sweden bloop
Life? What's that? Can I download it?! 
I accidontally smashed my keyboard while posting.
April 30th 2014, 05:55 PM
wizardg.gif
According to the reference it should. What's your script look like?
April 30th 2014, 06:02 PM
dragon.gif
Quiztis
Peasant He/Him Sweden bloop
Life? What's that? Can I download it?! 
Just a simple test script:

void main(void)
{
freeze(1);
loop:

wait_for_button();

if (&result == 68)
{
say("ass",1);
}

if(&result != 5)
{
goto loop;
}
unfreeze(1);
kill_this_task();


I noticed something. When the loop is running, Dink won't say ass when I press D, but if I hit ESC, then D, he will mysteriously say ass afterwards each time I press D.
April 30th 2014, 06:06 PM
wizardg.gif
It's going back to the loop every time because your check is !=5 when it should be != 68.

Or is button 5 ESC?

Point is, even if the player pushes D- they also push a button that goes into the != 5 check and the wait_for_button() loop starts again.
April 30th 2014, 06:11 PM
dragon.gif
Quiztis
Peasant He/Him Sweden bloop
Life? What's that? Can I download it?! 
Uh-huh, true. I ditched the one from the reference and tried this:

void main(void)
{
freeze(1);
loop:

wait_for_button();

if (&result == 68)
{
say("ass",1);
}

goto loop;

unfreeze(1);
kill_this_task();

Now, button 5 is ESC. If I try the above, it won't work at all! If I try if (&result == 5) though, Dink will say ass. The game is also frozen. dang
April 30th 2014, 06:14 PM
wizardg.gif
Doesn't wait_for_button freeze dink automatically? Try not using freeze();
April 30th 2014, 06:16 PM
dragon.gif
Quiztis
Peasant He/Him Sweden bloop
Life? What's that? Can I download it?! 
He isn't frozen by wait_for_button though. But why does it work for the standard keys (ctrl, space, esc, arrows) while he's frozen and not other keys?
April 30th 2014, 06:21 PM
wizardg.gif
I dunno, freeze() is weird man. Maybe someone who's used wait_for_button() before can tell you.
April 30th 2014, 06:23 PM
dragon.gif
Quiztis
Peasant He/Him Sweden bloop
Life? What's that? Can I download it?! 
Oh, gosh dang ignore all that in the previous post. I messed up. Freeze ain't the problem.

void main(void)
{
freeze(1);
loop:
wait_for_button();

if (&result == 68)
{
say("ass",1);
}

if (&result == 5)
{
say("ass",1);
}

goto loop;
}

Main problem: Dink will say ass when I press ESC, but not when I press D.
April 30th 2014, 07:05 PM
custom_magicman.gif
magicman
Peasant They/Them Netherlands duck
Mmmm, pizza. 
How about this script:

void main( void )
{
  freeze(1);
  wait_for_button();
  say("ass, button &result",1);
  unfreeze(1);
}


That's right, no loop, no if, nothing. The point of wait_for_button() is that it waits until a button has been pressed. If you don't see "ass" with a button value after pressing D, that means the engine doesn't think a button has been pressed. If that's the case, then I guess the answer is "because apparently the engine doesn't work that way". If you *do* see "ass" with a button value. Well. Then you now know what value to check for if you press D
May 1st 2014, 12:18 PM
dragon.gif
Quiztis
Peasant He/Him Sweden bloop
Life? What's that? Can I download it?! 
Huh, then I guess the engine doesn't work that way. It only registers the standard buttons for Dink.
May 1st 2014, 11:14 PM
peasantm.gif
shevek
Peasant They/Them Netherlands
Never be afraid to ask, but don't demand an answer 
Huh, then I guess the engine doesn't work that way. It only registers the standard buttons for Dink.

Yes, that's what DinkC.txt says about it as well. Then again, it also says that the M key is not recognized as button 6, but for me it is. Perhaps that changed from 1.07 to 1.08 or Freedink.
May 1st 2014, 11:39 PM
wizardg.gif
If you really need the player to push the D key, you could create a key68.c script and have a check for that particular instance when you want it used. You wouldn't need to use wait_for_button() in that case.
May 2nd 2014, 05:33 AM
dragon.gif
Quiztis
Peasant He/Him Sweden bloop
Life? What's that? Can I download it?! 
Hm, yeah I've been tinkering around with key-68. Wait_for_button is ideal for what I'm trying to do though, but thanks all anyways.
May 2nd 2014, 02:06 PM
custom_magicman.gif
magicman
Peasant They/Them Netherlands duck
Mmmm, pizza. 
I'll just go pimp run_script_by_number() again. If you put &current_script somewhere in a global, you can use that in a key script to jump to a procedure.

It's a bit of a roundabout way of doing things, though. Still, it may be of some use in some cases.

// somewhere in main.c
  make_global_int("&keyhandler",0);

// key-68.c
void main( void )
{
  if (&keyhandler > 0)
  {
    run_script_by_number(&keyhandler,"d");
  }
  kill_this_task();
}

// script.c
void main( void )
{
  int &d = 0;
}

void talk( void )
{
  if (&d > 0)
  {
    say_stop("Nope. Wrong button. Press D.",1);
    return;
  }

  say_stop("Oh. Looks like I have to press D to continue.",1);
  &keyhandler = &current_script;
  return;
d1:
  say_stop("Another bit of stuff here.",1);
  say_stop("Mind, you, to see more, press D again.",1);
  &keyhandler = &current_script;
  return;
d2:
  say_stop("That's it! Keep pressing that key!",1);
  &keyhandler = &current_script;
  return;
d3:
  say_stop("End of story.",1);
}

// I'm not too happy about this bit, but oh well. You could of course put the cutscene-stuff directly inside this.
void d( void )
{
  &keyhandler = 0;
  &d += 1;
  if (&d == 1)
  {
    goto d1;
  }
  if (&d == 2)
  {
    goto d2;
  }
  if (&d == 3)
  {
    goto d3;
  }
}


Also works great with spawn():

// In main.c
  make_global_int("&keyhandler",0);
  // Did you know: main.c gets run on game load as well!
  &keyhandler = spawn("keyhandler");

// keyhandler.c
void d( void )
{
  say("D",1);
}

// key-68.c
void main( void )
{
  if (&keyhandler > 0)
  {
    run_script_by_number(&keyhandler,"d");
  }
  kill_this_task();
}