Haxic - BASIC scripting for flash player

Archives Forums/General Discussion/Haxic - BASIC scripting for flash player

Warner(Posted 2010) [#1]
haXic is a BASIC-dialect for the Flash VM, with some tweaks.
Biggest tweak is using curly brackets instead of Next/EndIf etc.
You can either download it, or try it online.


Check it out here

Example code:
img = loadimage("sprite.png")
sprite = createsprite(img)

repeat
    if keydown(37) then move sprite, -4, 0
    if keydown(39) then move sprite, 4, 0
    if keydown(38) then move sprite, 0, -4
    if keydown(40) then move sprite, 0, 4
    update
until keyhit(27)


The license for this version is free-to-use.
You may not redistribute or modify it without permission, however, you can create games with haXic and put them on your site.

Last edited 2010


slenkar(Posted 2010) [#2]
i used haxe myself quite a bit, this looks interesting

how do you debug?


Warner(Posted 2010) [#3]
(edit)Open up 'program.txt' and edit the file. Then run either .swf or .htm to test it. I made a Notepad++ user defined language for this project. Originally, I was planning to intergrate the IDE in the same applet that runs the program. That way the project could run from a browser.


slenkar(Posted 2010) [#4]
oh ok Notepad++ would let you write the code and catch errors during compilation?
all i need is 'debuglog' after compilation


Warner(Posted 2010) [#5]
Ah, okay, didn't knew how to read 'debug'.. Errors are shown onscreen with a line number and column.


degac(Posted 2010) [#6]
Nice work.
I dont' know haXe project - it seems very interesting.
I think the 'program' is interpreted, right?, but do you have considered a Blitz2Flash converter? Or just easier, a converter from Blitz to 'your language' (give it a name!)?

PS: I will replace Key's constant with a 'proper name' like in BlitzMax, life will be easier!


Warner(Posted 2010) [#7]
Yes, interpreted indeed. Code->Op codes->VM.
haXe is pretty nice, I use it as a free AS compiler. Claims were made it is even faster than the Adobe compiler.
Well, I'm not too confident about that, though, but I would settle for 'almost as fast' as well.
Converting from Blitz would be difficult, since: which Blitz should I choose? BlitzMax is really extensive, and Blitz3D uses 3D.
So then it would be BlitzBasic-to-Flash. That might not be so convenient after all.
I did however consider writing a code-converter, but for this particulair project, my goal is to write a webbased programmig language: no install needed.
You know www.pixlr.com? It is a webbased paiting program. Very nice project.
Anyway, that means compilation has to be done from inside the applet, which rules out using haXe in the process.
I will include keycodes consts later on, but I'm not sure I find them easier: Most of the time, I'm still looking up their names: lctrl, leftctrl, lcontrol or leftcontrol? The codes themself are based on the original ASCII values that were there in the '80ies allready: 32=space 65=A 27=ESC 8=BACKSPACE. Cursor keys=37/39/38/40. And they are the same throughout different languages and platforms: BlitzMax, Java and Flash.


slenkar(Posted 2010) [#8]
I would like a blitzmax to haxic convertor but.....

in blitzmax you load an image and draw it

in flash you have to create sprites as in your examples

there is the 'copypixels' way of drawing but i dont think you have the same alpha, rotation and other commands

but actually graphics are a small part of the program and could be changed manually....


b32(Posted 2010) [#9]
I would create a translator from bmax to haxe instead. In ActionScript, you could use double-buffering, in the way you're describing: use a bitmapData as the BackBuffer. copyPixels does have rotation and scaling options built-in. They're not 'forwarded' to the haxic script call. I implemented the copyimage function later on, when I needed it for the platformer demo. Using sprites is a pretty convenient way of creating games, still. A big advantage is that the AVM uses a 'dirtyrect' method to update the screen, so only parts that change are refreshed. I will look into the rotate/scaling option for drawPixels, but first, I'd need to implement the more basic stuff, like functions, types and lists.


slenkar(Posted 2010) [#10]
something that tripped me up is the fact that Classes have to begin with a capital letter,
otherwise its an easy language to use


Warner(Posted 2010) [#11]
You mean in haXe?


slenkar(Posted 2010) [#12]
yes


Warner(Posted 2010) [#13]
Ah, I didn't notice that. Maybe I allready have a habit of starting Classes with a capital letter? If that is the biggest concern, it's not that bad.
Anyway, I uploaded a new version, with keyboard consts, the extended drawing command that uses scale/rotation and blendmode. Example added. Also, in the last version error messages were not visible, since they were written in black on a black background. Fixed that too.


agent4125(Posted 2010) [#14]
I have been looking for something like this for a while now. In fact, I used it this weekend for Ludum Dare and managed to create something pretty decent with it:

http://www.fleacircusgames.com/pee-wee-pirates/

Probably the biggest hangup was that it always errored out whenever I tried using while-type loops inside of functions. I had to use gosubs or recursion to get around that. Also, it was kind of a pain knowing when to use parens when calling functions.

Obviously I knew it was alpha when I started, though, and thankfully I was able to work around most of the limitations.

Anyway, let us know if you set up a project page/blog, I'd love to track its progress.


slenkar(Posted 2010) [#15]
good pirate game man


Warner(Posted 2010) [#16]
Nice game! I played it quite a few times today. I am honoured you did that using Haxic. Must have been quite a struggle working around those first bugs. I've set up a blog and addressed the problems you described:
http://haxic.wordpress.com/
Thanks for your feedback.


slenkar(Posted 2010) [#17]
could you create mods for games?
e.g. have a game written in haxe and then load in a weapon e.g. (sword dagger) coded in haxic from the server


Warner(Posted 2010) [#18]
I would use hscript, or even flash.Lib.eval for that.


Pax(Posted 2010) [#19]
Hey Warner, nice project!

Will it be extensible? like if people wants to add libraries like tweener?


Warner(Posted 2010) [#20]
Thank you. I had no plans in that direction so far, but I'll look into the possibility of user-created extensions.


Warner(Posted 2010) [#21]
Updated with online IDE and the Tween class, see link in first post.


slenkar(Posted 2010) [#22]
cool ill try it out soon


GaryV(Posted 2010) [#23]
my goal is to write a webbased programmig language
You mean like Run BASIC?


Warner(Posted 2010) [#24]
Heh, that looks really funny. Thanks for the link.
If you want to try it out, click on the image in the first post.
It is a link to the online version of the IDE.


slenkar(Posted 2010) [#25]
run basic is for backend, haxic is for front-end :)


slenkar(Posted 2010) [#26]
how easy do you think it would be to convert blitzmax - haxic?

also
how is execution speed compared to haxe?


Warner(Posted 2010) [#27]
Conversion: the engine works differently than BlitzMax. It works with Sprites. However, such a Sprite holds an image, and you can draw other images onto this image, so in theory, it is possible to work in a BMax-like way, with a backbuffer. For that, see the 'EX_DRAW.txt' example in the download version.
But any of the OOP-features of BMax are not supported. In that aspect, the language is closer to BlitzBasic.
It depends on what BMax program you're trying to convert. And maybe it is easier to rebuild it from the ground up.
Execution speed: I didn't compare. haXic is intended to write not-too-large webgames. I wrote tests to see if it was fast enough for that. In general, I find Flash execution quite slow, and I can imagine running an interpreted language with it is slower. On the other hand, I did optimize the VM execution routines by using function pointers.
The 'update' command syncs the execution to 24 fps. I did that to support slower machines. If you want to change the fps, use the 'graphics' command.


slenkar(Posted 2010) [#28]
ok thanks


jkrankie(Posted 2010) [#29]
This looks ace! I'll hopefully find some time to give it a try an make a little game for my site :)

Cheers
Charlie


Warner(Posted 2010) [#30]
That would be cool. If you encounter any issues, please let me know. I'll fix them as soon as possible.


Warner(Posted 2010) [#31]
I've included physics now. That is fun to play around with.
You can see a demo here:
http://members.home.nl/bramdenhond/haxic/physdemo.html
To try it out, either download haxic or visit the site: http://www.haxic.com


slenkar(Posted 2010) [#32]
impressive....most impressive


okee(Posted 2010) [#33]
Came across this in a search, it seems to be progressing nicely.
It can now compile to .swf.


EOF(Posted 2010) [#34]
This is very nice. I love seeing instant results (due to interpreted rather than compiled nature)

I am playing with the downloaded version now, and its quite weird seeing the haXic*.swf running in GOM player(!)

I want to get around to testing the flash-complied demos on my Galaxy S (as soon as I update to Froyo that is) but I don't know how the media is handled. The readme.txt states that media is not included in the *.swf


Warner(Posted 2010) [#35]
The 2nd version -still alpha, posted today- can include images. They are included as raw bitmap data, but the data is compressed with FP10's default zlib compression. The compiler app btw is not a real compiler. It is still an interpreter.

Last edited 2010


EOF(Posted 2010) [#36]
Warner, good stuff. I am liking HaXic
Any chance of additional flags so that ovals and rects can be rendered unfilled?
Just a small thing, drawoval is missing from the docs. I found it by chance though

Is createscreen() the same as:
myimage=createimage()
mysprite=createsprite(myimage)?

Would it be easy to implement a basic class/types system?

Last edited 2010


Warner(Posted 2010) [#37]
Thank you. I'll add drawoval to the doc. Must have overlooked it.
I'm not sure btw if this is the correct place to address issues like these. Maybe the devlog would be a better place instead.
But anyway, 'createscreen' will create a drawable bitmap, that is added to the root. I wanted to create something that allows for drawing directly onto the screen.
By default, images are not added to the root. That is why they are not visible.
You could create an image yourself and add it manually to the root. It would do the same thing as using createscreen. A sprite is not an image, it is a wrapper for an image. The idea is that you load a single image, and then create multiple sprites with it. That way, less memory is consumed.
You can create empty sprites using createsprite(null). They would behave as pivots. You can add other objects to it with setparent. The default "root" object is such an empty sprite. Sprites are added to it by default.
If you create a non-empty sprite, it's image is it's first child.

There are still some issues to work out. One issue I found is a floating point inaccuracy when reading/writing sprite coords.
For instance, if you move a sprite with:
t++
position sprite, getx(sprite) + sin(t), gety(sprite)

The sprite moves towards the left, while it shouldn't. I'm working on that.

As for the class system: depends on what you need it for. There is a way to connect properties to a sprite. Each sprite has an array that can be used:
sprite = loadsprite("test.png")
sprite:["lives"] = 3

or
const lives = 1
sprite:[lives] = 3


If you need a more abstract type system, for now you could use arrays:


I'll look into createing a more genuine class system, but I can't really tell how long it will take. But it now on my list.
If you find any issues, please tell me. I'll add them to my to-do list as well.

Last edited 2010


Dabhand(Posted 2010) [#38]
Pretty neat that! :)

Dabz


SLotman(Posted 2010) [#39]
The pyshics demo didn't load here for me, both on Firefox 2 or IE 8. I have Flash 10 installed.

On IE8 it keeps loading forever... on Firefox2, when I right click it says "Movie not loaded" (greyed out). But the Pirate game did work here.

Edit: Just that link posted above didn't load. The ones on the 'official' site all loaded fine!

Would be possible to get the generated swf and add stuff on it? I'm thinking about mochiads mainly.

Last edited 2010


Warner(Posted 2010) [#40]
The trouble with the physics engine was that it runs only under FP10. When I compiled the standalone version, I used FP9 for compatibility. It took a while to discover that the standalone version didn't run any of the physics code.
The generated .swf is just a normal .swf. You can do with it what you can also do with common .swfs. There might be some issues regaring loading haXic applets.
In the meanwhile, I looked into mochiads, but I can't seem to find out how it works. If these ads use a flash library that is compiled along with the rest of your .fla, then I'm afraid you cannot use them.
You can however open other .swfs by using the OpenMovie command. And there is some functionality available to communicate with either javascript or php.


EOF(Posted 2010) [#41]
EDIT:
Now registered with the haXc forums and posted there


1. Do Cos/Sin work in degrees or radians?
2. Do you have the reference.pdf in any other format (such as HTML)? I would like to reorganize commands into categories such as math, graphics, input, file system, sound, etc
3. Do you plan to expand the IDE? I am thinking a nice little feature would be a box at the bottom which gives a quick reference to the current commands parameters/usage
4. Can you add the handy Trim command which removes tabs and spaces from either end of a string?
5. Also, I would like to see exit and continue commands for loop control

Thanks so far though. What currently exists is more than fun to play around with!

Last edited 2010


okee(Posted 2010) [#42]
2. Do you have the reference.pdf in any other format (such as HTML)? I would like to reorganize commands into categories such as math, graphics, input, file system, sound, etc


I used http://www.pdftoword.com/ to convert to an editable file but haven't
had a chance to arrange the commands


Warner(Posted 2010) [#43]
I answered there, at the site's forum. But I forgot to answer: sin/cos are in degrees, not radians.


Warner(Posted 2011) [#44]
This program is now open source. Here is a link:
http://code.google.com/p/haxic/