Help with buttons

Posted By: Harstad

Help with buttons - 01/12/09 16:12

HI, first of all, I'm new to this.

well, as you might guess, I'm here to ask you to help me.
I'm going through the workshop and made some panels and tried to add a button, but I can't seem to get to press the button.

well, here's the code:

#include <acknex.h>
#include <default.c>

function main ()
{
video_mode = 7;
screen_color.blue = 150;
mouse_mode = 4;
}


BMAP* background = "second.bmp";
BMAP* gras = "gress.bmp";

PANEL* new_background =
{
pos_x = 0;
pos_y = 0;
bmap = background;
layer = 1;
flags = VISIBLE;
}

PANEL* new_ground =
{
pos_x = 0;
pos_y = 0;
bmap = gras;
button (10, 10, "button_clicked.bmp", "button_unpressed.bmp", "button_pressed.bmp", quit_program, NULL, NULL);
layer = 2;
flags = OVERLAY | VISIBLE;
}

function quit_program()
{

while (key_any) {wait (1);}
sys_exit (NULL);
}
Posted By: Cowabanga

Re: Help with buttons - 01/12/09 16:25

change function quit_program to this:
Code:
function quit_program()
{
     sys_exit(NULL);
}


and change function main to this:
Code:
function main()
{
     video_mode = 7;
     screen_color.blue = 150;
     mouse_mode = 2;
     mouse_map = mouse_bmap;
     while(1)
     {
          mouse_pos.x = mouse_cursor.x;
          mouse_pos.y = mouse_cursor.y;
     }
}


and add this line in your script:
Code:
BMAP* mouse_bmap = "mouse.pcx";

(replace "mouse.pcx" by your cursor sprite)
Posted By: Harstad

Re: Help with buttons - 01/12/09 17:09

I changed it to this, as you said:
But now it hangs up when I try to compile it:P guess its not my day:P

#include <acknex.h>
#include <default.c>

BMAP* mouse_bmap = "mouse.bmp";
BMAP* background = "second.bmp";
BMAP* gras = "gress.bmp";

PANEL* new_background =
{
pos_x = 0;
pos_y = 0;
bmap = background;
layer = 1;
flags = VISIBLE;
}

PANEL* new_ground =
{
pos_x = 0;
pos_y = 0;
bmap = gras;
button (10, 10, "button_clicked.bmp", "button_unpressed.bmp", "button_pressed.bmp", quit_program, NULL, NULL);
layer = 2;
flags = OVERLAY | VISIBLE;
}

function quit_program()
{
sys_exit (NULL);
}

function main ()
{
video_mode = 7;
screen_color.blue = 150;
mouse_mode = 2;
mouse_map = mouse_bmap;
while (1)
{
mouse_pos.x = mouse_cursor.x;
mouse_pos.y = mouse_cursor.y;
}

}

though, if I take away the while (1) { mouse_pos.x ....... mouse_cursor.y;} it works fine, but I can't move the mouse inside the game:P:P

may there be an issue with vista32?
Posted By: Mr Wurm

Re: Help with buttons - 01/13/09 00:25

naw no issue with vista, you have just created an endless loop...
while(1) <-until killed
{
perform this and this
wait(1); <-pause for a frame, to allow all the other functions to work and to allow the engine to render etc.
}

So: insert a wait(1); at the end of the while(1) loop and it will cease to crash and start to work.
Posted By: Cowabanga

Re: Help with buttons - 01/14/09 11:48

Yeah! I've forgot!

Code:
function main()
{
     video_mode = 7;
     screen_color.blue = 150;
     mouse_mode = 2;
     mouse_map = mouse_bmap;
     while(1)
     {
          mouse_pos.x = mouse_cursor.x;
          mouse_pos.y = mouse_cursor.y;
          wait(1);
     }
}

© 2024 lite-C Forums