binding/callback + 'update' + "_"

55 views
Skip to first unread message

Ma rk

unread,
Aug 29, 2014, 9:12:22 AM8/29/14
to haxe...@googlegroups.com
hi guys,

Please accept my excuse if the question is too generic or trivial (or simply dumb - this is how I feel now tbh :) but the more sources I involve to try to figure out this part of Haxe, the more confused I get.

So. I don't perfectly understand how 'update', 'callbacks' and '_' denotes are supposed to work. First, I have these here:
Manual, Binding:       http://haxe.org/manual/lf-function-bindings.html
Small timer test code: http://try.haxe.org/#45cfC

* In the timer sample code, it looks like it goes against the concept of binding/callbacks. Also, it seems "onGameOver" is an event handler but it's just a Void AND(???? HUH ???? :) Dynamic

* Manual is not very detailed so found me a bit confused around "_", as well as not mentioning "update()" which looks a 'special' function:
From what I learned it seems a class which is implementing this, gets updated on every frame. Is that true? Or...
And when "a frame happens" e.g.
in a windows binary? Is that "common"? What if I have a superfast monster? - I have many questions around this. And I found no clear answer.

* Also, found a site offering sample codes (http://deepnight.net/) but these are -intentionally- truncated as well as old (haxe2) codes (either way, the guy's blog is nice and it's still MUCH of help, though)


So what I need is, and I understand it's time consuming so a complete answer would be much appreciated: either a few good pages/docs (haxe3), or, even better, a sample code that can compile to cpp as well as flash*, explaining in details how
event mechanism and callbacks actually work.

Thank you for all the trouble in advance!


All the Best,
Mark

* == This is my biggest fear: Let's say I learn into Haxe and start coding a game (game.dev. is also new to me, but what life would be without challenges, right? :).
And I want to run this game on both Flash and Desktop (Win/Mac/Lin) with the same code base. Do I have to implement event handling several times and on different ways to make this happen? Which means, do I need to brench codebases after all? Or write it in Flash and wrap to desktop (yuck)?
Or there's a technique/library allows me to do this in one go and it handles for me the platform issues?
My, my! So much to learn!

dlots

unread,
Aug 29, 2014, 9:43:17 AM8/29/14
to haxe...@googlegroups.com
http://en.wikipedia.org/wiki/Anonymous_function

That code doesn't have anything to do with binding.

Binding is a convenience utility that generates an anonymous function wrapping a function, with the wrapped function called with the bound arguments and whatever left over arguments being the arguments of said generated anonymous function.

Simon Krajewski

unread,
Aug 29, 2014, 10:22:01 AM8/29/14
to haxe...@googlegroups.com

You mix multiple concepts here that have nothing to do with each other. Haxe has no notion of any special update function, and it is certainly not related to function binding.

I cannot explain more right now because I am typing on a tablet.

Simon

--
To post to this group haxe...@googlegroups.com
http://groups.google.com/group/haxelang?hl=en
---
You received this message because you are subscribed to the Google Groups "Haxe" group.
For more options, visit https://groups.google.com/d/optout.

Ma rk

unread,
Aug 29, 2014, 10:22:38 AM8/29/14
to haxe...@googlegroups.com
included it just as seen update function implemented like this at a few places in some sample codes:

static function update(_) {

I don't know what do you mean by "the code". The 'try.haxe.org' one does not use '_' at all.

Simon Krajewski

unread,
Aug 29, 2014, 10:24:17 AM8/29/14
to haxe...@googlegroups.com

This is probably convention for "I do not care about the argument".

Simon

Ma rk

unread,
Aug 29, 2014, 10:25:15 AM8/29/14
to haxe...@googlegroups.com
Yes, sorry for the "mixture" - see my reply to dlots.

Related to "update", code syntax (at least in Scite for Haxe set as language) highlights it + in the sample codes I've seen so far these are never called from anywhere (might be the caller was just truncated?).

Thank you in advance if you plan to give more details when you reach a desktop :)

Dan Korostelev

unread,
Aug 29, 2014, 10:25:42 AM8/29/14
to haxe...@googlegroups.com
Hey there!


* In the timer sample code, it looks like it goes against the concept of binding/callbacks. Also, it seems "onGameOver" is an event handler but it's just a Void AND(???? HUH ???? :) Dynamic
It's just a function that can be overriden (thus dynamic) - see more here: http://haxe.org/manual/class-field-dynamic.html
 
* Manual is not very detailed so found me a bit confused around "_",
I don't see "_" in that code example, but mostly it just used for arguments that you don't care about and don't want to introduce a local name for.
 
as well as not mentioning "update()" which looks a 'special' function:
It's nothing special, you call it in your Timer.run in that example. 
 
From what I learned it seems a class which is implementing this, gets updated on every frame. Is that true? Or...
Nope :-P
 
And when "a frame happens" e.g. in a windows binary? Is that "common"? What if I have a superfast monster? - I have many questions around this. And I found no clear answer.
Haxe doesn't have anything to do with frames and stuff, it all depends on the library/framework you use, such as OpenFL, Flambe, Kha or whatever.
 
So what I need is, and I understand it's time consuming so a complete answer would be much appreciated: either a few good pages/docs (haxe3), or, even better, a sample code that can compile to cpp as well as flash*, explaining in details how event mechanism and callbacks actually work.
You're probably looking for OpenFL - a haxe framework implementing cross-platform Flash API, so you can do that "code flash then compile to native" thing.
 
Reply all
Reply to author
Forward
0 new messages