2 registered members (AndrewAMD, Quad),
608
guests, and 5
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Panel event runs only for one frame?
#353657
01/12/11 03:19
01/12/11 03:19
|
Joined: Jan 2011
Posts: 120 United States
Logan
OP
Member
|
OP
Member
Joined: Jan 2011
Posts: 120
United States
|
Hi, I'm Logan. I used to post on here 3-4 years ago, and then kinda moved on in life--but now I'm back, kinda, itching to noodle around at least until school starts up again. I'm working on an adventure game with some RPG elements. Yeah, the same one as waaaay long ago. Trying to finish it so I can finally die happy. I'm working on a click-n-drag feature for a specific panel, and I wrote this code:
function popupbox_click_event();
PANEL* popupbox =
{
bmap = popupbox_map;
layer = 4;
event = popupbox_click_event;
}
function popupbox_click_event()
{
while(mouse_left)
{
popupbox.pos_x += mickey.x;
popupbox.pos_y += mickey.y;
wait(1);
}
}
It doesn't work. If I am dragging the mouse AS I click on it, it moves a few pixels in the direction the mouse was moving. That's evidence to me that the while loop ran, but only once. I've tried proc_mode = PROC_GLOBAL; as well as changing the loop to while(1) just for experimentation's sake. Even worse, if I add a wait(1) to the beginning of the event function, nothing happens at all. This looks like a bug to me, but I thought I would run it by here before posting in the Bug Hunt forum in case I am missing something obvious, or if this has already been discussed, or something. I really appreciate anyone's help. This community is awesome.
|
|
|
Re: Panel event runs only for one frame?
[Re: Logan]
#353681
01/12/11 08:34
01/12/11 08:34
|
Joined: Feb 2009
Posts: 84 Deutschland/Niedersachsen
GorNaKosh
Junior Member
|
Junior Member
Joined: Feb 2009
Posts: 84
Deutschland/Niedersachsen
|
Hello out there, I throw some code together, to give xou an example. Here it comes:
BMAP *testPanel = "test.png";
BMAP *mousePointer = "arrow.pcx";
function popupbox_click_event(PANEL* pPanel);
PANEL* popupbox =
{
pos_x = 10;
pos_y = 10;
bmap = testPanel;
event = popupbox_click_event;
flags = VISIBLE;
}
function popupbox_click_event(PANEL* pPanel)
{
while(mouse_left)
{
pPanel.pos_x = mouse_pos.x;
pPanel.pos_y = mouse_pos.y;
wait(1);
}
}
function main() {
mouse_mode = 2;
mouse_map = mousePointer;
while(mouse_mode > 0) {
vec_set(mouse_pos, mouse_cursor);
wait(1);
}
}
This script is tested and works fine for me. I think the problem are this lines of your script:
popupbox.pos_x += mickey.x;
popupbox.pos_y += mickey.y;
I fairly don't know how to deal with the mickey var, but to set the panel position to the mouse position every frame, is a handy solution as well. Just try it. Hope it helps in spite of my bad english Gor Na Kosh
|
|
|
Re: Panel event runs only for one frame?
[Re: Logan]
#353696
01/12/11 11:17
01/12/11 11:17
|
Joined: Nov 2010
Posts: 96 Vienna
Schubido
Junior Member
|
Junior Member
Joined: Nov 2010
Posts: 96
Vienna
|
Hi, I had a similar problem doing a while(...) {... wait(1) ...} within an entity event. It seemed that it ran just for one frame. The manual says that you should not use wait(1) in entity events - maybe thats also true for panel events. So maybe it could help to do the panel movement in a seperate function and just set a trigger in the panel event. Something like ...
var popupboxDrag = 0;
function popupbox_click_event();
PANEL* popupbox =
{
bmap = popupbox_map;
layer = 4;
event = popupbox_click_event;
}
function popupbox_click_event()
{
popupboxDrag = 1
}
function popupboxAction()
{
while(1)
{
if(popupboxDrag)
{
popupboxDrag = 0;
while(mouse_left)
{
popupbox.pos_x += mickey.x;
popupbox.pos_y += mickey.y;
wait(1);
}
}
wait(1);
}
}
main()
{
...
popupboxAction();
...
}
|
|
|
Re: Panel event runs only for one frame?
[Re: Schubido]
#353697
01/12/11 11:38
01/12/11 11:38
|
Joined: Jul 2008
Posts: 1,178 England
MrGuest
Serious User
|
Serious User
Joined: Jul 2008
Posts: 1,178
England
|
Hi, I had a similar problem doing a while(...) {... wait(1) ...} within an entity event. It seemed that it ran just for one frame. The manual says that you should not use wait(1) in entity events - maybe thats also true for panel events. So maybe it could help to do the panel movement in a seperate function and just set a trigger in the panel event. Something like ...
var popupboxDrag = 0;
function popupbox_click_event();
PANEL* popupbox =
{
bmap = popupbox_map;
layer = 4;
event = popupbox_click_event;
}
function popupbox_click_event()
{
popupboxDrag = 1
}
function popupboxAction()
{
while(1)
{
if(popupboxDrag)
{
popupboxDrag = 0;
while(mouse_left)
{
popupbox.pos_x += mickey.x;
popupbox.pos_y += mickey.y;
wait(1);
}
}
wait(1);
}
}
main()
{
...
popupboxAction();
...
}
as GorNaKosh said you shouldn't be using += for the position. Though neither of you take account for moving it from where is was click and always aligning directly to the mouse position. Try this. It uses a button rather than giving the whole panel the click event, just change it as required.
#include <acknex.h>
#include <default.c>
PANEL* pnl_dummy;
void move_panel(var id, PANEL* pnl){
int x = mouse_pos.x - pnl.pos_x;
int y = mouse_pos.y - pnl.pos_y;
while(mouse_left){
pnl.pos_x = mouse_pos.x - x;
pnl.pos_y = mouse_pos.y - y;
wait(1);
}
}
void main(){
mouse_mode = 4;
wait(1);
pnl_dummy = pan_create("", 1);
pnl_dummy.bmap = bmap_createblack(100, 60, 32);
bmap_fill(pnl_dummy.bmap, COLOR_GREEN, 100);
set(pnl_dummy, SHOW);
BMAP* bmp_moveBtn = bmap_createblack(100, 10, 32);
bmap_fill(bmp_moveBtn, COLOR_RED, 100);
pan_setbutton(pnl_dummy, 0, 0, 0, 0, bmp_moveBtn, bmp_moveBtn, bmp_moveBtn, bmp_moveBtn, move_panel, NULL, NULL);
}
|
|
|
Re: Panel event runs only for one frame?
[Re: Logan]
#353981
01/14/11 16:13
01/14/11 16:13
|
Joined: Sep 2003
Posts: 6,861 Kiel (Germany)
Superku
Senior Expert
|
Senior Expert
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
|
Moral of the story is that the is() macro doesn't return 1's and 0's per se, so don't set a variable to it as though it returns a numerical value. Short explanation: The macro "is" is defined as follows: #define is(obj,flag) (obj->flags & (flag)) The flag "SHOW" is defined as follows: #define SHOW (1<<14) That means if you write is(panel1,SHOW), that translates to (panel1->flags & SHOW) what is equal to 2^14.
Last edited by Superku; 01/14/11 16:17.
"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual Check out my new game: Pogostuck: Rage With Your Friends
|
|
|
Re: Panel event runs only for one frame?
[Re: Superku]
#354042
01/14/11 23:31
01/14/11 23:31
|
Joined: Jul 2008
Posts: 1,178 England
MrGuest
Serious User
|
Serious User
Joined: Jul 2008
Posts: 1,178
England
|
Moral of the story is that the is() macro doesn't return 1's and 0's per se, so don't set a variable to it as though it returns a numerical value. Short explanation: The macro "is" is defined as follows: #define is(obj,flag) (obj->flags & (flag)) The flag "SHOW" is defined as follows: #define SHOW (1<<14) That means if you write is(panel1,SHOW), that translates to (panel1->flags & SHOW) what is equal to 2^14. lol, that's one way to confuse the forumees... if that's a word you could just try
freeze_mode = 2-freeze_mode;
|
|
|
|