REALLY new with Haxe

Not a modern programmer here but I can get around with various languages.
Failing with my first Haxe script.
Copied this script from a tutorial and calling it with the Script logic node fired off by a keyboard key:

class HelloWorld {
static public function main():Void {
trace(“Hello World”);
}

First it failed to compile, looking like the “” were a problem so I changed those single quotes and now my game will compile. However, hitting the key to execute the script sends nothing to the Blender console.
Man, going from Lua to Haxe is a major reality-check lol!

1 Like

Hi. We all need to start anew at some point in life and learn new things for many things, so don’t feel too bad.

Armory already provides a default Haxe script template whenever creating a new Haxe script.

After creating your new Haxe script, your script should look like this:

package arm;

class MyTrait extends iron.Trait {
	public function new() {
		super();

		// notifyOnInit(function() {
		// });

		// notifyOnUpdate(function() {
		// });

		// notifyOnRemove(function() {
		// });
	}
}

Here’s a script that will output "Hello World" on Armory load and also print "Spacebar was pushed" whenever you push your Spacebar key.

package arm;
import iron.system.Input;

class MyTrait extends iron.Trait {
	public function new() {
		super();

		notifyOnInit(function() {
			trace('Hello World');
		});

		notifyOnUpdate(function() {
			if (Input.getKeyboard().started('space')) {
				trace('Spacebar was pushed');
			}
		});
	}
}

If you want to use the newer arrow functions, and only use 1 code line inside the curly braces, you can simply remove the curly braces too.

package arm;
import iron.system.Input;

class MyTrait extends iron.Trait {
	public function new() {
		super();

		notifyOnInit(() -> trace('Hello World'));

		notifyOnUpdate(() -> if (Input.getKeyboard().started('space')) trace('Spacebar was pushed'));
	}
}

Feel free to use whatever code syntax / style you’d prefer, including using single or double quotes. I honestly don’t care.

1 Like

thanks for the info so far; can’t get past this point.
-Tied this Trait to my camera object.
-Running in Blender gives console error:
(unknown) : Package “arm.beaver” was not found in any of class paths
-In VSCode tried ‘Run without Debugger’ command, so I…um…selected Haxe Interpreter. That does nothing but cause this console message:
[main 2023-10-09T01:41:25.987Z] update#setState idle
[main 2023-10-09T01:41:26.748Z] WSL is not installed, so could not detect WSL profiles
[main 2023-10-09T01:41:55.996Z] update#setState checking for updates
[main 2023-10-09T01:41:56.031Z] update#setState idle

At the moment I’m pretty clueless about any of this. Hopefully I can get past the Hello World stage and get to work. I know exactly what I need to do now: open a PNG file into a 2D array with each element holding the color (indexed PNG in this case). I’ve already done the code that converts cursor position to a lat/long position relative to the camera direction so the hard work is done!
I don’t suppose it’s possible to open a PNG file into a 2D array with Logic Nodes?

Actually there is some confusioin in that last result. Here is a cleaner failure message from Blender when trying to run from there:
D:\1107-Arm\Sources/arm/Liar.hx:11: characters 8-13 : Type not found : Input

Could you please share your whole project folder (blend + all armory sources) here. If you’d prefer instead, you can also share it in private via direct messing.

Hopefully this works!
Three files:
Project folder
Armory folder, including the custom Krom file to fix the large image file issue.
Also included the Blender settings folder in case there is something important there. (I’m on Windows so may not be useful to Apple or Linux user)

You forgot to include the import for the Input module:

import iron.system.Input;

Look at my second or third script from my last post above.

awesome, it works!; I thought there might be an import somewhere but decided it was built in.
Can you give me a pointer to where to start importing a library for reading/decoding image files?
(not in particular, just basics of how to integrate a separate library in the context of Armory3D; I’ve never been comfortable with extended software environments and dependencies)

banging away at getting an external library to work; found this tutorial but can’t make it work.

Added just this text to my trait code, “using hx.strings.Strings” as shown in the tutorial.
I get this console report:
D:\D - Downloads\Armory\armsdk/nodejs/node.exe D:\D - Downloads\Armory\armsdk/Kha/make krom -g direct3d11 --shaderversion 330 --parallelAssetConversion 4 --to build_arm3/debug --quiet --nohaxe --noproject
D:\D - Downloads\Armory\armsdk/Kha/Tools/windows_x64/haxe.exe --connect 6000 project-krom.hxml
Finished in 1.908s
D:\D - Downloads\Armory\armsdk/Krom/Krom.exe D:\1107-Arm\build_arm3/debug/krom D:\1107-Arm\build_arm3/debug/krom-resources --consolepid 29752
Trace: TypeError: Cannot read properties of undefined (reading ‘platform’)
at :81214:82
at :81217:2
at :81601:3

Sorry, I never was able to figure out how import 3rd-party Haxe libraries.

That’s because that tutorial was based on legacy Armory, back when Armory was a fork of Blender.

Is there a source of the help I need around somewhere? Not being able to use an external library kills a lot of the resources I expected from a game engine. (playing videos as patches or full-screen cut-scenes is the other major capability I need)
Actually that seems like a real con when trying to pitch Armory to the public.

I occurred to me that Blender has built-in video capabilities for moving textures but I just read that when exported none of those Blender-y things will be included.
I have a dedicated Scene to play my intro movie. It just has an ortho camera looking at a plane with a movie texture. Entering that scene will automatically play the timeline, then jump to the main game Scene.
But how do I trigger the animation and detect when it is finished and trigger a scene change? A python script supposedly won’t work since there is no python environment in an exported game, or so Ive read.
Maybe using Actions, since I see those in Armory but I’ve never gotten a handle on how to use those and those control keyframes anyway; a video has no keyframes (that I know of…maybe…)
I also see that Kha has a video class, but that is so outside Blender I won’t look closer unless I’m desperate!

Armory can import external Haxe libraries, I just was never able to figure out how on a general basis. Last year, one of the Armory developers was able to integrate an external Haxe library so that Armory could support networking (for all platforms except Krom):