MaxGUI event hook usage - need help!

BlitzMax Forums/MaxGUI Module/MaxGUI event hook usage - need help!

codermax(Posted 2012) [#1]
Ok, so I had the same problem as many others, I couldn't get the sliders to fire the events I wanted. It turns out, I had to put the whole event loop inside the hook function. Otherwise, EVENT_GADGETACTION would NEVER be fired! That's the only one event I have trouble catching(apparently, hook functions HATE EVENT_GADGETACTION). I tried to set it up in a WaitEvent() handler, and the dang thing would only execute "window usage" stuff, and not the slider code I have.

Now here's the problem... Showing any hidden gadgets crashes the program! This ONLY happened when I "fixed" the whole EVENT_GADGETACTION mess. Before, everything worked fine and I could mess with windows no prob.

Do you guys know how many days it took for me to find the ONE POST that had the solution to the whole slider BS in it? A whole week! BRL's site search isn't very powerful, so I had to search EVERY DAY for specific phrases and stumble upon JUST the right post. And now that I found the solution that makes my problem area work, It makes me sad to know a bigger problem emerged from it. :(

Here's the code from the available files. Most of the code from say, the main loop or the draw files aren't worth looking at, it's mostly the event handling stuff that's of interest, but I wanted to make sure the entire source was available, because someone might find a problem I couldn't have!

If you want the code to "work" like before so you could see what broke, simply take the event code out of the hook function and put it inside a regular function like the "process_event" one already made or whatever.

smm_main.bmx:


smm_draw.bmx:


smm_input.bmx:


smm_event.bmx:


Last edited 2012


col(Posted 2012) [#2]
Hiya,

I've not got a lot of time to go through with a fine toothed comb but here are some tips:-

First thing is the main logic is wrong. You should have WaitEvent() outside of the hook function and in the upper most outer mainloop, so move it from the MyHook function to the first instruction after the While in the While/WEnd loop at the end of the main file.

This will then show up many many errors. Some are below...

- Don't use RedrawGadget in the EVENT_GADGETPAINT as it would cause a recursive loop. Use the EVENT_TIMERTICK event to do your drawing.
- Use Event.*field* inside the MyHook function, NOT the MaxGui EventData(),EventID() and associated functions.
-Use Flip 0 so as NOT to wait for the vertical blank. You're using a timer for frame timing.

As I said I've not got a lot of time to rectify all the errors as I have to go out now, but I've made a start going through the hook function ( I had to indent the code to make it readable for myself ) :-




TaskMaster(Posted 2012) [#3]
Do a google search like this:

site:blitzmax.com "your search terms here"

Google search is much better and it will search this site very well.


codermax(Posted 2012) [#4]
Hi col!

Thanks for pointing me in the right direction! I guess the code structure is the way it is because of MaxGUI. :p The Event variable extraction functions seemed to work just as well.
This code also contains many of my attempts to "fix" it. I will make the suggested changes and see what happens next, and I will keep you posted!

And thanks for the search tip TaskMaster(I love playing as you in Marvel 3! Your arrows are beast :D)

EDIT: I got it all to work! Thanks everyone! Hopefully this post will help others who are having trouble with this stuff. :)

Last edited 2012


col(Posted 2012) [#5]
Glad its working now.

Just for your notes and hopefully help any possible future hook event related issues...

The Event variable extraction functions seemed to work just as well.


The hook function is called with an Event and its datas, so you should use those that are passed into the hook function. If you use EventID() inside a hook then you could and do get a different ID from the one that's involved in the hook, probably from the next event in the queue. As an example to see this in action :- in your MyHook function put a Print EventID() followed by Print Event.ID just before the first Select and you'd expect to see the same results printed twice, but alas.... you don't!

Hope it helps :P


TaskMaster(Posted 2012) [#6]
And thanks for the search tip TaskMaster(I love playing as you in Marvel 3! Your arrows are beast :D)


HA... That is where I actually got the name. Not that video game, but from a Marvel Comic years and years ago. I think it was an Ant-Man comic, probably 30 years ago; TaskMaster was a cool villain.