1

Okay, I am working on a menu and how it works is every 3 seconds a new option comes up, but I am trying to make it so that within that 3 second period I can press a button to activate something now look here:

dvar(-1, 0, "e \"Prestige and rank settings\"");
Sleep(35);
dvar(-1, 0, "c \"Set prestige one\"");
if (Key_Down(0, 0x02)) {
  dvar(-1, 0, "c \"Setting 1st prestige, will be kicked\"");
  Sleep(1000);
  dvar(-1, 0, "c \"^43\"");
  Sleep(1000);
  dvar(-1, 0, "c \"2\"");
  Sleep(1000);
  dvar(-1, 0, "c \"^41\"");
  Sleep(1000);
}
Sleep(3000);

The issue above is after "Set prestige one" it skips to the next Sleep(3000) and to the next option, now I need to find a way to be able to still use that if statement witch is a button within that 3 seconds, rather then it Sleeping the thread and making the button unusable unless you press it before the text loads.

So pretty much what I need to do is rather then Sleep the thread instead make it wait those 3 seconds so I can still use that if statement.

THIS IS FOR A DLL RUNNING ON A XBOX360

Libs currently in use

#include "stdafx.h"
#include < stdio.h >
#include <string>
#include <iostream>
j.w.r
  • 4,136
  • 2
  • 27
  • 29
Mike Smith
  • 39
  • 4
  • On what operating system? (if it is some Posix or Linux system, you need `sleep` or `usleep`, and perhaps `poll`) – Basile Starynkevitch Sep 15 '12 at 06:11
  • 4
    This is an event based programming problem. There are many libraries with event loops that should be able to solve your problem. What libraries are you using to do this application that you are writing? Perhaps with that someone will be able to answer your question properly. – Horus Sep 15 '12 at 06:12
  • I've updated it it's for a xbox360 and I'm not 100% if any extra libs can be added hence its for a xbox. – Mike Smith Sep 15 '12 at 06:15
  • @basile-starynkevitch I replied above! – Mike Smith Sep 15 '12 at 06:30
  • Shit, I've asked over 62 people, no one has a clue saying it's not possible witch makes my application pointless and a waste of over 600 lines of code. – Mike Smith Sep 15 '12 at 08:29
  • @MikeSmith it's definitely possible, but you need to change the structure of your code to be event-driven instead of explicitly blocking. This has wider implications than just on the code you posted. – pmdj Sep 15 '12 at 14:41

1 Answers1

0

I think you would try to programming with following minds::

  1. Event driven.
  2. Multi thread. using system timer event service.
  3. State machine based.

Pseudo Code is like this::

int State = IDLE;
dvar(-1, 0, "e \"Prestige and rank settings\"");
Sleep(35);
dvar(-1, 0, "c \"Set prestige one\"");

while (1)
{
    switch (SomeEvent)
    {
    case ON_Key_down:
        if (Key == 0x02)
        {
            if (State == IDLE || State == KEY_PRESSED_SET1stPRESTIGE_Finish)
            {
                State = KEY_PRESSED_SET1stPRESTIGE_1stSTEP;
                dvar(-1, 0, "c \"Setting 1st prestige, will be kicked\"");

                Timer_Event_AfterMS(1000);   // make request event after 1sec to system alarm service
            }
            else
            {
                // ignore do something
            }
        }
        break;
    case ON_Timer_SomeSec:
        if (State == KEY_PRESSED_SET1stPRESTIGE_1stSTEP)
        {
            dvar(-1, 0, "c \"^43\"");
            State = KEY_PRESSED_SET1stPRESTIGE_2ndSTEP;
            Timer_Event_AfterMS(1000);   // make request event after 1sec to system alarm service
        }
        else if (State == KEY_PRESSED_SET1stPRESTIGE_2ndSTEP)
        {
            dvar(-1, 0, "c \"2\"");
            State = KEY_PRESSED_SET1stPRESTIGE_3rdSTEP;
            Timer_Event_AfterMS(1000);   // make request event after 1sec to system alarm service       
        }
        else if (State == KEY_PRESSED_SET1stPRESTIGE_3rdSTEP)
        {
            dvar(-1, 0, "c \"^41\"");
            State = KEY_PRESSED_SET1stPRESTIGE_4rdSTEP;
            Timer_Event_AfterMS(1000);   // make request event after 1sec to system alarm service       
        }
        else if (State == KEY_PRESSED_SET1stPRESTIGE_4rdSTEP)
        {
            State = KEY_PRESSED_SET1stPRESTIGE_Need3SEC;
            Timer_Event_AfterMS(3000);   // make request event after 3sec to system alarm service       
        }
        else if (State == KEY_PRESSED_SET1stPRESTIGE_Need3SEC)
        {
            State == KEY_PRESSED_SET1stPRESTIGE_Finish;
        }
        break;
    default:
        break;
    }
}