eventcodes

BlitzMax Forums/BlitzMax Beginners Area/eventcodes

CS_TBL(Posted 2005) [#1]
Call me a lunatic, but I rather type these hex codes than all that event_longword stuff all the time. I knew all B+ eventcodes by heart after 2 or 3 days of using them.. doesn't take long to get used to.

Question is: do these codes remain the same throughout all future bmax updates? If yes, there's no problem using the codes :P

DebugLog Hex$(EVENT_APPSUSPEND)
DebugLog Hex$(EVENT_APPRESUME)
DebugLog Hex$(EVENT_APPTERMINATE)
DebugLog Hex$(EVENT_KEYDOWN)
DebugLog Hex$(EVENT_KEYUP)
DebugLog Hex$(EVENT_KEYCHAR)
DebugLog Hex$(EVENT_MOUSEDOWN)
DebugLog Hex$(EVENT_MOUSEUP)
DebugLog Hex$(EVENT_MOUSEMOVE)
DebugLog Hex$(EVENT_MOUSEWHEEL)
DebugLog Hex$(EVENT_MOUSEENTER)
DebugLog Hex$(EVENT_MOUSELEAVE)
DebugLog Hex$(EVENT_TIMERTICK )
DebugLog Hex$(EVENT_HOTKEYHIT )
DebugLog Hex$(EVENT_MENUACTION)
DebugLog Hex$(EVENT_WINDOWMOVE)
DebugLog Hex$(EVENT_WINDOWSIZE)
DebugLog Hex$(EVENT_WINDOWCLOSE)
DebugLog Hex$(EVENT_WINDOWACTIVATE)
DebugLog Hex$(EVENT_WINDOWACCEPT)
DebugLog Hex$(EVENT_GADGETACTION)
DebugLog Hex$(EVENT_GADGETPAINT)
DebugLog Hex$(EVENT_GADGETSELECT)
DebugLog Hex$(EVENT_GADGETMENU)
DebugLog Hex$(EVENT_GADGETOPEN)
DebugLog Hex$(EVENT_GADGETCLOSE)
DebugLog Hex$(EVENT_GADGETDONE)


Perturbatio(Posted 2005) [#2]
the reason they use constants is so that they numeric values can be changed without changing your code.


FlameDuck(Posted 2005) [#3]
Question is: do these codes remain the same throughout all future bmax updates?
No. That's why they use constants.

If yes, there's no problem using the codes :P
The question you want to be asking is not "Is there a problem with hardcoding values into my application" (although the answer for this is yes). The question you should be asking yourself is "Why would I want to".

Remember in the old days when you used to hardcode absolute addresses in your assembly code, instead of using labels and relative addresses like sensible people? Remember how much distress that caused all your friends with different RAM configuration than you? Same deal, different day.


CS_TBL(Posted 2005) [#4]
Why would I want to? Because something like $4003 is faster to type than EVENT_WINDOWCLOSE .. that's the only reason. I've done so with B+.

Hm.. I could ofcourse make my own shorter constants to these event_ contstants..

const E4003=EVENT_WINDOWCLOSE springs to mind ^_^


FlameDuck(Posted 2005) [#5]
Because something like $4003 is faster to type than EVENT_WINDOWCLOSE
Learn to type faster then. :o>

Seriously, while typing $4003 might be a split second faster than typing EVENT_WINDOWCLOSE (which doesn't require awkward use of the shift button I might add), the benefits to readability by far outwiegh any real or imagined "waste" time spent hitting those extra keys. Come back to it 5 years down the line, and you'll be greatful you did. Traditionally, long term maintenance costs make up 80% of the total lifecycle costs, so it pays off to plan ahead.


Perturbatio(Posted 2005) [#6]
it's entirely up to you what you do, if you want to redefine the constants, go ahead. But if there comes the time where you work on a project with someone else, expect headaches, either yours when trying to relearn the constants, or theirs trying to figure out what the hell you were playing at when you redefined the constants.


Azathoth(Posted 2005) [#7]
This is one thing BlitzBasicII had against it, there is no reason to go back using hex numbers for this kind of thing.


bradford6(Posted 2005) [#8]
const EWC = EVENT_WINDOWCLOSE

or if you don't like typing get Dragon Naturally speaking and say it.

I'm with FlameDuck on this one though. EVENT_WINDOWCLOSE is a very descriptive variable and makes the code readable and easier to maintain.

(maybe you're first BMAX program can be a typing tutor :)


Banshee(Posted 2005) [#9]
I find all caps lock words as unreadable in code as they are in the posts of forum trolls, it turns your code into something ressembling an MSDN TechNet document - which has got to be a sin so severe that i'll burn in hell just for having done it once. I type it as 'event_windowClose', i'd do away with the underscore too if I could be bothered to redefine the constant...


xlsior(Posted 2005) [#10]
Seriously, while typing $4003 might be a split second faster than typing EVENT_WINDOWCLOSE (which doesn't require awkward use of the shift button I might add)


How exactly is a _ 'less awkward use of the shift button' than a $ ? (on a standard US/International keyboard the _ is also a shift key)

But I do agree that having the descriptive names is much easier to work with than numeric identifyers -- a lot quicker to glance over old code, for one.


FlameDuck(Posted 2005) [#11]
How exactly is a _ 'less awkward use of the shift button' than a $ ?
Because you can keep shift pressed the whole time while typing it.


I find all caps lock words as unreadable in code
Hmm. I like the idea of using case to differentiate between CONSTANTS, Classes and members.


rdodson41(Posted 2005) [#12]
CS_TBL, I was the same way with BlitzPlus, I just memerized the event codes and used those, in the same way that I type 27 instead of KEY_ESCAPE. I would prefer to do the same with BlitzMax, but if they ever do change in the future it might cause some headaches.


Hotcakes(Posted 2005) [#13]
Yes. For example, KEY_ESCAPE used to be 1 =]


CS_TBL(Posted 2005) [#14]
sushi: that was more or less my point: 'will they ever change things?'

I mean, $4001 is uhm.. 16385 .. I figure that those eventcodes are at least shorts but probably ints. In case of ints, we have an awful lot of codes available. How big is the chance that 'windowclose' moves to another spot? We won't be short of event-locations I guess. I can imagine events are added, .. but 'replaced' ?? With int values for eventcodes, I'd simply assign another one..

And the same with key codes.. 1 is known. But 8 11 13 34 65 200 203 205 208 are also quite known ^_^


rdodson41(Posted 2005) [#15]
Yeah, but I found out that BMX uses the real ascii values for keys instead of whatever made up system B+ had. And since I know most of the ascii values that you would regularly need in a game, I don't see much need for the long names.

But what you are saying CS_TBL is that it wouldn't be hard for them to change the eventcodes around if they need to add new ones or replace old ones. So until BRL says something regarding this I would just use the constants.


Perturbatio(Posted 2005) [#16]
If you want anyone else to be able to use your code properly, use the constants.


CS_TBL(Posted 2005) [#17]
well, an IDE with code-completion would also help ofcourse :P