Giter Site home page Giter Site logo

godot-nim's People

Contributors

arikrahman avatar arunvickram avatar beef331 avatar bluenote10 avatar dsrw avatar endragor avatar geekrelief avatar jrenner avatar jyapayne avatar kosz78 avatar shalokshalom avatar zetashift avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

godot-nim's Issues

Ambiguity for button methods

import godot
import engine, h_box_container, node, base_button

gdobj HUD of HBoxContainer:
  var timescale: float32
  var paused: bool
  var topStatusText: string

  method ready*() =
    setProcess(true)

  method process*(delta: float64) =
    let stop = findNode("Stop") as TextureButton
    paused = stop.pressed()
    if paused:
      topStatusText = "Paused"
    else:
      topStatusText = "In progress..."

    findNode("Top Status Bar").setText(topStatusText)

nake build gives me an error:

hud.nim(7, 7) template/generic instantiation from here
hud.nim(17, 18) Error: ambiguous call; both base_button.pressed(self: BaseButton)[declared in /home/survivor/g-engine/godot/_godotapi/base_button.nim(80, 5)] and base_button.pressed(self: BaseButton)[declared in /home/survivor/g-engine/godot/_godotapi/base_button.nim(197, 7)] match for: (TextureButton)

Looking into the source i certanly find a proc pressed(self: BaseButton) and a method pressed(self: BaseButton). And IIRC compiler has no way to destinguish them in such a case

Cannot compile on windows 10?

Cannot generate dll file on windows. I install visual studio 2017 and c++ build tools. I found there cl.exe and added to path (because nim cannot find it). At the end this time it says below message;

Error: execution of an external compiler program 'vccexe.exe /c --platform:amd64 /nologo /Z7 -DWIN32_LEAN_AND_MEAN /Od  /IC:\nim\lib /FoD:\gamedev\castle_fight\src\.nimcache\windows\amd64\stub_stub.obj D:\gamedev\castle_fight\src\.nimcache\windows\amd64\stub_stub.c' failed with exit code: 2

cl.exe /c /nologo /Z7 -DWIN32_LEAN_AND_MEAN /Od /IC:\nim\lib /FoD:\gamedev\castle_fight\src\.nimcache\windows\amd64\stub_stub.obj D:\gamedev\castle_fight\src\.nimcache\windows\amd64\stub_stub.c
stub_stub.c
C:\nim\lib\nimbase.h(255): fatal error C1083: Cannot open include file: 'limits.h': No such file or directory
       Tip: 11 messages have been suppressed, use --verbose to show them.
     Error: Execution failed with exit code 1
        ... Command: "C:\nim\bin\nim.exe" c --noNimblePath --path:"C:\Users\oelibol\.nimble\pkgs\godot-0.7.14" --path:"C:\Users\oelibol\.nimble\pkgs\compiler-0.18.0" "-o:..\_dlls\nim_64.dll"  "..\src\stub.nim"

I tried to find limits.h in visual studio and added to INCLUDE env variable that path but this time it cannot find stddef.h. Am I missing something?

Crashes in android

Hello! I successfully built godot-nim-stub for android (my fork: https://github.com/DrMoriarty/godot-nim-stub)
It starts and shows correct fps counter. But it crashes when I pressed the main scene. I added some debug output in https://github.com/DrMoriarty/godot-nim-stub/blob/master/src/mainpanel.nim
so log is:

06-27 00:22:28.057: D/GODOT(632): ** GODOT ACTIVITY CREATED HERE ***
06-27 00:22:28.077: D/AccessibilityManager(632): current package=org.godotengine.godotnimstub, accessibility manager mIsFinalEnabled=false, mOptimizeEnabled=true, mIsUiAutomationEnabled=false, mIsInterestedPackage=false
06-27 00:22:28.398: D/GODOT(632): command_line is null? no
06-27 00:22:28.447: I/godot(632): **INIT EVENT! - 0xf3e19310
06-27 00:22:28.447: I/godot(632): ***************** HELLO FROM JNI!!!!!!!!
06-27 00:22:28.447: I/godot(632): *******CLASS FOUND!!!
06-27 00:22:28.447: I/godot(632): STEP2, 0x10096e
06-27 00:22:28.447: I/godot(632): STEP3 -410202076
06-27 00:22:28.447: I/godot(632): STEP4, 0x20001d
06-27 00:22:28.447: I/godot(632): STEP4.5, 0x100972
06-27 00:22:28.448: I/godot(632): STEP7
06-27 00:22:28.448: I/godot(632): STEP8
06-27 00:22:28.448: I/godot(632): *******GOT METHOD _dir_open ok!!
06-27 00:22:28.448: I/godot(632): *******GOT METHOD _dir_next ok!!
06-27 00:22:28.448: I/godot(632): *******GOT METHOD _dir_close ok!!
06-27 00:22:28.448: I/godot(632): *******GOT METHOD _dir_is_dir ok!!
06-27 00:22:28.448: I/godot(632): starting to attempt get methods
06-27 00:22:28.448: I/godot(632): *******GOT METHOD _init_audio ok!!
06-27 00:22:28.448: I/godot(632): *******GOT METHOD _write_buffer ok!!
06-27 00:22:28.448: I/godot(632): *******GOT METHOD _quit ok!!
06-27 00:22:28.448: I/godot(632): *******GOT METHOD _pause ok!!
06-27 00:22:28.448: I/godot(632): test construction 5
06-27 00:22:28.448: I/godot(632): running from dir /
06-27 00:22:28.466: I/godot(632): **SETUP
06-27 00:22:28.466: I/godot(632): CMDLINE LEN 2 - APK EXPANSION 0
06-27 00:22:28.507: I/godot(632): *****SETUP OK
06-27 00:22:28.507: I/godot(632): ANDROID MODULES: Nothing to load, aborting
06-27 00:22:28.517: I/godot(632): WARNING: not found: display/driver/keep_screen_on
06-27 00:22:28.543: D/GODOT(632): setVirtualKeyboardHeight: 0
06-27 00:22:28.548: I/Adreno(632): QUALCOMM build                   : 53b4b64, I83a540a04a
06-27 00:22:28.548: I/Adreno(632): Build Date                       : 09/18/17
06-27 00:22:28.548: I/Adreno(632): OpenGL ES Shader Compiler Version: XE031.09.00.04
06-27 00:22:28.548: I/Adreno(632): Local Branch                     : 
06-27 00:22:28.548: I/Adreno(632): Remote Branch                    : quic/gfx-adreno.lnx.1.0.r5-rel
06-27 00:22:28.548: I/Adreno(632): Remote Branch                    : NONE
06-27 00:22:28.548: I/Adreno(632): Reconstruct Branch               : NOTHING
06-27 00:22:28.669: I/OpenGLRenderer(632): Initialized EGL, version 1.4
06-27 00:22:28.669: D/OpenGLRenderer(632): Swap behavior 1
06-27 00:22:28.672: W/GodotView(632): creating OpenGL ES 3.0 context :
06-27 00:22:28.684: I/godot(632): ^_^_^_^_^ newcontext 0
06-27 00:22:28.684: I/godot(632): ^_^_^_^_^ resize 0, 1440, 720
06-27 00:22:28.685: I/godot(632): **FIRST_STEP
06-27 00:22:28.697: I/godot(632): OpenGL ES 3.0 Renderer: Adreno (TM) 506
06-27 00:22:28.749: I/godot(632): OpenSL Init OK!
06-27 00:22:28.754: I/libOpenSLES(632): Emulating old channel mask behavior (ignoring positional mask 0x3, using default mask 0x3 based on channel count of 2)
06-27 00:22:28.766: W/AudioTrack(632): AUDIO_OUTPUT_FLAG_FAST denied by client; transfer 1, track 44100 Hz, output 48000 Hz
06-27 00:22:28.769: D/AudioTrack(632): Client defaulted notificationFrames to 590 for frameCount 1772
06-27 00:22:29.072: I/Choreographer(632): Skipped 32 frames!  The application may be doing too much work on its main thread.
06-27 00:22:29.273: I/godot(632): Main panel is ready
06-27 00:22:30.679: D/GODOT(632): setVirtualKeyboardHeight: 0
06-27 00:22:42.508: V/BoostFramework(632): BoostFramework() : mPerf = com.qualcomm.qti.Performance@619cbc6
06-27 00:22:42.519: I/godot(632): Main panel have input
06-27 00:22:42.519: I/godot(632): Main panel have mouse pressed
06-27 00:22:42.519: I/godot(632): Main panel have left mouse button pressed
06-27 00:22:42.541: I/godot(632): We are changed the scene
06-27 00:22:46.179: E/godot(632): **ERROR**: Unhandled exception: Error: unhandled exception:  [NilAccessError]
06-27 00:22:46.179: E/godot(632):    At: /Users/vasya/.nimble/pkgs/godot-0.7.14/nim/godotnim.nim:838:() - Unhandled exception: Error: unhandled exception:  [NilAccessError]
06-27 00:22:46.179: E/godot(632): **ERROR**: Unhandled exception: Error: unhandled exception:  [NilAccessError]
06-27 00:22:46.179: E/godot(632):    At: /Users/vasya/.nimble/pkgs/godot-0.7.14/nim/godotnim.nim:838:() - Unhandled exception: Error: unhandled exception:  [NilAccessError]

The last two lines repeated more than 100 times and then application closes.
I tried to change compilation flags. I disabled threads and tlsEmulation but it have absolutely no effect.

Also I changed android compilation from clang to gcc because of errors (https://forum.nim-lang.org/t/3981) I don't know if it affect to this issue.

Macosx: 10.13.4
Godot: 3.0.4
Android: 7.1.2
Android NDK: r14b

Instanced scene won't show in editor

Hiya I'm currently following this: http://kidscancode.org/blog/2018/04/godot3_tanks_part4/
Everything going well so far and I have the all the code done from part4 but the instanced bullet scene isn't showing when running the game. The code runs through it, since I put some debug messages and the position and direction are showed correctly.

    proc onTankShoot*(bullet: Variant,
                      position: Variant,
                      direction: Variant) {.gdExport.} =
        
        var b = asObject[PackedScene](bullet).instance() as PlayerBullet

        var pos = position.asVector2
        var dir = direction.asVector2
        print(pos)
        print(dir)
        print("adding bullet to the mapscene")
        self.addChild(b)
       b.start(pos, dir)

Full project files are here: https://github.com/zetashift/toptanksnim
So everything runs fine except that no bullets are showing up at all.

Nim 0.19

I'm just wondering if the bindings are going to be updated to compile with the latest nim version 0.19. As of now, there is the error:

godotapigen.nim(9, 26) Error: type mismatch: got <string>
but expected one of:
proc getIdent(ic: IdentCache; identifier: string): PIdent
proc getIdent(ic: IdentCache; identifier: string; h: Hash): PIdent
proc getIdent(ic: IdentCache; identifier: cstring; length: int; h: Hash): PIdent

expression: getIdent(ident)

which can be solved as mentioned in #32 (comment). But after that, there are still errors regarding string nil checks (strings can't be nil anymore in 0.19). And even if I use the option --nilseqs:on for backwards compatibility other errors show up. I would love to see the Nim bindings updated,

CanvasItem drawPolygon NilAccess

While trying to draw a polygon with the drawPolygon or drawColoredPolygon functions of a CanvasItem node, I get the following error

ERROR: : Unhandled Nim exception (NilAccessError):
godotmacros.nim(569)     methFunc
map2D.nim(57)            draw
canvas_item.nim(797)     drawPolygon
godotnim.nim(433)        godotObject

I'm using the function as follow:

drawPolygon(points, colors, newPoolVector2Array())

I think the problem is I'm using the default value of the texture which is nil, and the code tries to pass this nil texture as a godot object:

proc drawPolygon(self: CanvasItem; points: PoolVector2Array; colors: PoolColorArray;
                uvs: PoolVector2Array; texture: Texture = nil;
                normalMap: Texture = nil; antialiased: bool = false) =
...
let argToPassToGodot3 = texture.godotObject # <= This is the line 797 of canvas_item.nim

Am I supposed to pass a not nil texture for this to work? I just want to draw a filled polygon with plain color.

Cannot open include file: 'windows.h'

The error I got running nake build after updating to nim version 0.17.3

Error: execution of an external compiler program 'vccexe.exe /c --platform:amd64 /nologo /Z7 -DWIN32_LEAN_AND_MEAN /Od  /ID:\Nim\lib /FoZ:\Programming\Nim\Godot\Nimbreak\src\.nimcache\windows\amd64\stdlib_dynlib.obj Z:\Programming\Nim\Godot\Nimbreak\src\.nimcache\windows\amd64\stdlib_dynlib.c' failed with exit code: 2

"C:\WINDOWS\system32\cmd.exe" /C ""C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall" amd64 && SET"
cl.exe /c /nologo /Z7 -DWIN32_LEAN_AND_MEAN /Od /ID:\Nim\lib /FoZ:\Programming\Nim\Godot\Nimbreak\src\.nimcache\windows\amd64\stdlib_dynlib.obj Z:\Programming\Nim\Godot\Nimbreak\src\.nimcache\windows\amd64\stdlib_dynlib.c
stdlib_dynlib.c
Z:\Programming\Nim\Godot\Nimbreak\src\.nimcache\windows\amd64\stdlib_dynlib.c(11): fatal error C1083: Cannot open include file: 'windows.h': No such file or directory
       Tip: 11 messages have been suppressed, use --verbose to show them.
     Error: Execution failed with exit code 1
        ... Command: "D:\Nim\bin\nim.exe" c --noNimblePath --path:"C:\Users\XXXX\.nimble\pkgs\godot-0.7.7" --path:"C:\Users\XXXX\.nimble\pkgs\compiler-0.17.3" "-o:..\_dlls\nim_64.dll"  "..\src\stub.nim"

Let me know if there's anything I can try to sort this issue out, for now I'm just going to create an issue.

Vector operators don't seem to work

It's hard to tell which of them aren't working, but for example this:

print vec2(1, 0) + vec2(0, 1)

prints 1, 0, whereas if I define my own + method:

proc `+`(a, b: Vector2): Vector2 = vec2(a.x + b.x, a.y + b.y)
print vec2(1, 0) + vec2(0, 1)

it prints 1, 1 as expected.

Also using += gives me a stack overflow and crashes, but maybe I'm not using it correctly:

var a = vec2(1, 0)
var b = vec2(0, 1)
a += b
print a

Thus I have to resort to using a = a + b instead, which only works with my + override above. I am unable to create a corresponding += override because I get "a.x cannot be assign to".

Can't build sample app on Mac, environment variable not working

Hi, I installed everything according to https://pragmagic.github.io/godot-nim/master/index.html and followed the steps in the README. I get a peculiar error when running nake build:

โžœ  platformer-nim nake build
Compiling nakefile...
GODOT_BIN environment variable is not set
โžœ  platformer-nim echo $GODOT_BIN
/Applications/Godot.app/Contents/MacOS/Godot
โžœ  platformer-nim

As you can see, it is complaining GODOT_BIN is not set when it really is. Some info about my computer:
Macos 10.14.6
Tested with both Zsh and Bash

Does anyone have any suggestions for getting around this? Am I setting this up correctly?

nimble installs the 0.3.0 version

Hi, I followed the stub project readme to install godot-nim on my Linux machine then nake complains about godotapigen module.

Here is the files installed by nimble.

capture du 2017-08-02 16-58-04

I guess nimble has installed an outdated version.

nake loops forever when something fails

Nake keeps trying to repeat the task when something fails. I had to change the line in nakefile.nim...

direShell(["nimble", "c", ".."/"src"/"stub.nim", "-o:.."/"_dlls"/libFile])

to

shell(["nimble", "c", ".."/"src"/"stub.nim", "-o:.."/"_dlls"/libFile]) 

... so that nake quits when the build fails.

I'm on Windows 7, if that makes any difference.

The same thing was happening a few days ago when I had no clue what I was doing, and the effect was that it just kept opening and closing godot on me, over and over, and repeating the message that it couldn't generate api.json.


On a related note, when it loops due to failed build it also tries to generate the entire godot api from scratch inside src\src folder, because apparently direShell never returns and withDir "src" is still in effect, and iirc it endlessly creates a new src folder inside the last src folder, each with an entire new godot api inside.

Preload a scene and create instance?

Is it possible to preload a scene and create an instance from inside Nim?

i.e. in GDScript:

var gameunit = preload("res://GameUnit.tscn")

func spawnUnit():
    var inst = gameunit.instance()

Update README and docs to show this works with Nim 1.2 and Godot 3.2

Hi I just followed the instructions for the Godot Nim stub with Nim v1.2 and Godot 3.2.1 stable and was able to run the example. So far so good.

I'm new to Nim and Godot, but it seems like the lack of updates to the docs, might scare people into thinking Nim isn't viable with Godot. Can you update the README and docs?

Building fails on current devel

untouched godot-nim-stub, running on arch linux

[rama@home myproject]$ nake build
Compiling nakefile...
OpenGL ES 3.0 Renderer: GeForce GTX 1070/PCIe/SSE2
Generating audio_stream_player_2d.nim...
Generating shape_2d.nim...
Generating dynamic_font_data.nim...
Generating light_2d.nim...
Generating primitive_mesh.nim...
Generating shader.nim...
Generating mobile_vr_interface.nim...
Generating scene_tree_timer.nim...
Generating editor_file_dialog.nim...
Generating packed_scene.nim...
Generating visual_script_function.nim...
Generating animation.nim...
Generating visual_script_sub_call.nim...
Generating video_player.nim...
Generating http_client.nim...
Generating sky.nim...
Generating animation_player.nim...
Generating sprite_base_3d.nim...
Generating polygon_path_finder.nim...
Generating capsule_mesh.nim...
Generating visual_script_constructor.nim...
Generating kinematic_collision.nim...
Generating geometry_instance.nim...
Generating groove_joint_2d.nim...
Generating translation_server.nim...
nake.nim(93)             moduleHook
nakelib.nim(252)         runTask
nakefile.nim(29)         :anonymous
nakefile.nim(26)         genGodotApi
godotapigen.nim(1002)    genApi
renderer.nim(1442)       renderTree
renderer.nim(635)        gstmts
renderer.nim(546)        gsub
renderer.nim(1254)       gsub
renderer.nim(609)        gsection
renderer.nim(1160)       gsub
renderer.nim(546)        gsub
renderer.nim(1127)       gsub
renderer.nim(546)        gsub
renderer.nim(1167)       gsub
renderer.nim(546)        gsub
renderer.nim(1174)       gsub
renderer.nim(1341)       gsub
renderer.nim(321)        gcoms
renderer.nim(318)        gcom
renderer.nim(226)        putComment
system.nim(2857)         sysFatal
Error: unhandled exception: index out of bounds [IndexError]

and with an existing project:

stub/game/world/character/blocky/player.nim(5, 7) template/generic instantiation from here
/home/rama/.nimble/pkgs/godot-0.7.14/nim/godotmacros.nim(403, 35) Error: undeclared field: ''

Not builds godot api

Nim version - devel, latest(01 Jun 2018)
Nake - 1.9.2, 1.9.1 has other error
GoDot 3.0.2-3

./nakefile clean; GODOT_BIN=/usr/bin/godot nake build
Compiling nakefile...
OpenGL ES 3.0 Renderer: Mesa DRI Intel(R) HD Graphics 530 (Skylake GT2) 
Generating audio_stream_player_2d.nim...
Generating shape_2d.nim...
Generating dynamic_font_data.nim...
Generating light_2d.nim...
Generating primitive_mesh.nim...
Generating shader.nim...
Generating mobile_vr_interface.nim...
Generating scene_tree_timer.nim...
Generating editor_file_dialog.nim...
Generating packed_scene.nim...
Generating visual_script_function.nim...
Generating animation.nim...
Generating visual_script_sub_call.nim...
Generating video_player.nim...
Generating http_client.nim...
Generating sky.nim...
Generating animation_player.nim...
Generating sprite_base_3d.nim...
Generating polygon_path_finder.nim...
Generating capsule_mesh.nim...
Generating visual_script_constructor.nim...
Generating kinematic_collision.nim...
Generating geometry_instance.nim...
Generating groove_joint_2d.nim...
Generating translation_server.nim...
nake.nim(93)             moduleHook
nakelib.nim(252)         runTask
nakefile.nim(29)         :anonymous
nakefile.nim(16)         genGodotApi
godotapigen.nim(957)     genApi
renderer.nim(1424)       renderTree
renderer.nim(626)        gstmts
renderer.nim(537)        gsub
renderer.nim(1236)       gsub
renderer.nim(600)        gsection
renderer.nim(1142)       gsub
renderer.nim(537)        gsub
renderer.nim(1109)       gsub
renderer.nim(537)        gsub
renderer.nim(1149)       gsub
renderer.nim(537)        gsub
renderer.nim(1156)       gsub
renderer.nim(1323)       gsub
renderer.nim(312)        gcoms
renderer.nim(309)        gcom
renderer.nim(217)        putComment
system.nim(2843)         sysFatal
Error: unhandled exception: index out of bounds [IndexError]

AutoLoad Singleton using Nim?

I currently have 2 nim, player.nim and game_state.nim files containing a KinematicBody2D(as Player classname) and a Node2D(as a GameState classname).
I also have a Global script as an AutoLoad script, however in my corresponding 'global.nim' which tracks the current gameState and player, I can't set/get anything without introducing recursive importing problems, which is obvious since Global imports player.nim and game_state.nim but those 2 files also import global so they can set the correct state in Global from their ready() methods.

What would be the Nim way(TM) without introducing importing problems?

Example request

Can you elaborate an example like code in GDScript and same code in godot-nim.
I have a vague idea, how it would look like, but not quite sure i'm right. Of cource I may apply try and see approach, but i'm quite positive on that i'm not the only one with such problems.
For example:
From Jaynam tutorial https://www.youtube.com/watch?v=kc-zJnRvPUY

extends Camera

export var distance = 12.0
export var height = 4.0

func _ready():
	# Called every time the node is added to the scene.
	# Initialization here
	set_physics_process(true)
	set_as_toplevel(true)  # Independant from the parent position


func _physics_process(delta):
	var target_position = get_parent().get_global_transform().origin
	var camera_position = get_global_transform().origin
	var up = Vector3(0, 1, 0)

	var camera_offset = camera_position - target_position

	camera_offset = camera_offset.normalized()*distance
	camera_offset.y = height

	camera_position = target_position + camera_offset

	look_at_from_position(camera_position, target_position, up)

will be transformed to

some code

And also you need to add script, choose NativeScript, choose class name from nim code, and (some other things)


This things are pretty simple, i'm almost sure it all revolves around gdobj macro, but there are some unclear points.
Like name translation rules (CamelCase to underscore_delimited and back), using inherited procs (like look_at_from_position in this ex.), using methods of GD core objects (like Input.is_action_pressed) and so on. Then do i need to write custom toVariant/fromVariant/godotTypeInfo and then it may be crated automatically (and is there any such case)?
All of this questions may be solved by simple but throughout example. Step-by-Step, from binding to the editor object till running scene.
This may be a little boring for you, but it will greatly help people who start their very first godot+nim project.

Not working with master branch.

Hi, this library is not working with master branch of Godot although nativescript 1.1 doesn't break compatibility with Godot 3.0 (only adds more functionality). I tested on linux, and it seems there is some problem while registering nim classes because Godot complains about it when it tries to load the shared library. Right now I'm not on my computer, but later on I can specify which error messages throws godot when tries to load nim shared library.

Edit: With Godot 3.0 is working fine, but Godot 3.0 has some bugs that they are fixed on master branch, so knowing that is backward compatible we should be able to use it with master branch. I think this way more users will be attracted to this awesome bindings.

0.20, stub, windows -> cannot open file: engine

I installed godot 3.0 and followed the godot-nim Getting Started docs. I have an existing nim 0.20.0 and nimble. Trying to build the stub, there were errors. Using nimble install https://github.com/aguspiza/godot-nim#head and requires "https://github.com/aguspiza/godot-nim#head" in stub.nimble fixed many of the errors.

I forked that repo and got through the remaining error and even got rid of warnings which were mostly caused by changes to NimNode after 0.18. The remaining error involved removing the {.immediate.} pragma from the macro gdobj in godotmacros.nim(630). I also forked the stub with my change.

I'm now getting the error:

godot-nim-stub\src\fpscounter.nim(5, 8) Error: cannot open file: engine

Any ideas or suggestions? Do I just need to be on 0.18? I saw a comment above godotmacros.nim(630)

# immediate macros are deprecated, but `untyped` doesn't make it immediate,
# as the warning and the documentation claim.

Could this be causing the error I'm seeing? I don't need to have the godot_headers somewhere and pass/include to nim compiler do I? Hoping there is someway to use 0.20 as choosenim is broken on windows afaik.

Getting errors using {.gdExport.} pragma

I'm using Godot 3.2_rc1 and Nim 1.0.4 (should I use older versions?)

I'm getting an error when I use {.gdExport.} on initialization fields. For example:

import godot
import godotapi/node_2d

gdobj SimpleTest of Node2D:
    var derp* {.gdExport.} = 10 
C:\Godot\Godot-Nim\simple_test\src\simple_test.nim(4, 7) 
       template/generic instantiation of `gdobj` from here
C:\Users\Skaruts\.nimble\pkgs\godot-0.7.26\nim\godotmacros.nim(406, 21) 
      Error: undeclared identifier: 'typeInfo`gensym1145165'

I also tried using hints and hintStrs, but nothing seemed to work.

That pragma works on procs though.

Usage

Can you explain how to install and use this? I know you just created and are working on this project and that's of course why there aren't any docs, but I would love to start using it and helping out where I can.

Api generation fails

After following the instructions to build godot nim-stub, i get the following error:

NimRL\src\fpscounter.nim(5, 17) Error: cannot open file: godotapi/engine Tip: 4 messages have been suppressed, use --verbose to show them. Error: Execution failed with exit code 1 ... Command: "C:\Program Files\nim-1.2.2\bin\nim.exe" c --noNimblePath -d:NimblePkgVersion=0.1.0 --path:"C:\Users\porra\.nimble\pkgs\godot-0.8.0" --path:"C:\Users\porra\.nimble\pkgs\compiler-1.2.2" "-o:..\_dlls\nim_64.dll" "..\src\stub"

I dont know what else to do.

[Question] Install latest working version

Hello! I'm trying to use Godot with Nim but the latest version is not working. I tried to use an older version (0.7.8) but I don't know how to install it correctly. I downloaded the zip file and extracted it to /home/user/.nimble/pkgs because I don't know how to install it using nimble directly. When I tried to compile the "godot-nim-stub" I got an error saying "nakefile.nim(5, 8) Error: cannot open 'godotapigen'". How do I install the latest working version?

Thanks in advance! =)

Nested project folder

I've tried a couple times throughout the history of this project to have everything in project live at the root directory instead, so that godot's res:// root can access the root dir. I was never able to get it working, despite updating all paths that refer to project, and all relative paths.

I'm fine working against the grain on this assuming I can get it working, but it makes me want to ask why you made project a subdirectory. I feel like it doesn't make sense to have to arbitrarily put all assets (including images, models, and other gdscript-agnostic files) inside a nested folder in the project.

I know this is a rather minor complaint, but I'm making a godot yeoman generator that will have godot-nim integration from the beginning, and conditionally nesting the godot files based on whether users want to use nim is really weird and wouldn't play well with other languages people might add in the future, but always nesting it is just as weird since it doesn't make any sense in a normal godot project.

How to use external C/C++ libraries?

Hi,
im new to nim in general so i need some help.
e.g. i want to use https://github.com/Auburns/FastNoise in my project.

I tried to write a wrapper module for testing but without any luck. For now i want the GetValue Function.

fastnoise.nim

{.push header: "FastNoise.h".} 

type
  FastNoise* {.importcpp: "FastNoise".} = object

#proc constructFastNoise*(seed: cint = 1337): FastNoise {.constructor.}
proc GetValue*(this: FastNoise, x: cfloat, y: cfloat): cfloat {.importcpp.}
#proc SetSeed*(this: FastNoise; seed: cint) {.importcpp.}

{.pop.}

generate.nim

proc GetNoise() =
    var obj: FastNoise
    print($obj.GetValue(5, 8))

First, where to put .h and .cpp files? and what is the path? do i need to link them anywhere? In the example above the compiler can't even find the FastNoise.h, I put it together with generate.nim and fastnoise.nim in /src.

And is the code above the right way to do it? It's my second day with nim, so please bear with me.

Use getNode to modify label text?

Hiya. Sorry to bother, but I couldn't figure this particular problem out on my own.
I'd like to use getNode on a label in order to modify it, but I'm not sure if the syntax is correct. Here is some example code.

gdobj counter_controller of Control:
    var current_clicks_node: Node

    method ready*() =
        self.current_clicks_node = getNode(self, newNodePath("stats/v_box_container/current_clicks"))
        print(self.current_clicks_node.get_text())
        #self.current_clicks_node.text = "GDNative is working"

Something similar to this would work in GDScript in order to modify the label text, but here it says that get_text, getText, .text =, etc aren't valid procs. I imagine it's because I'm working on a Node object, but I'm not sure what to do about it.

Recursive dependencies of gdobj

I'm trying to get a state machine module of mine ported from GDScript to Nim.

In GDScript, I had a state.gd and state_machine.gd, both extensions of Node. Each State instance has a member pointing to its StateMachine parent, and each StateMachine keeps a reference of its child States.

Translating this to Nim, I started with import state and state_machine into each other. However, naturally I run into a recursive type dependency this way. Normally, as I understand Nim (only a couple week's experience), the go-to way to solve this is to define both in a single type declaration, a la

type
  State = ref object
    ... 
  StateMachine = object
    ...

But I can't figure out how to get this to play with types defined with the gdobj macro.

The farthest I've gotten to solving this so far is a single states.nim file, like so:

import
  godot, node

type
  State = object of Node

gdobj StateMachine of Node:
  ...

gdobj State of Node:
  ... 

I run into a new issue here:

gdobj StateMachine of Node:
  ...
  method ready*() =
    self.HOST = get_parent() as Node

    for state in get_children():
      # I tried `state of State` here, but was getting "Error: 'Variant:ObjectType' can never be of this subtype"
      if state is State:
        let as_state: State = state as State
states.nim(36, 37) Error: type mismatch: got <Variant, type State>
but expected one of: 
proc `as`[T: NimGodotObject](obj: NimGodotObject; t: typedesc[T]): T
  first type mismatch at position: 1
  required type: NimGodotObject
  but expression 'state' is of type: Variant
proc `as`[T: NimGodotObject](obj: NimGodotObject; t: typedesc[T]): T
  first type mismatch at position: 2
  required type: type T: NimGodotObject
  but expression 'State' is of type: type State

expression: state as State

It seems that the State type isn't being understood as a NimGodotObject (even if it is of Node?), nor is state understood as a NimGodotObject (even if it is of Variant).

I suspect this all comes back to my type statement, which is effectively a bandaid solution to the original recursive import problem. So, with this in mind, how should I be handling recursive imports with gdobj-defined types, or how can I better define my types with this solution?

Also, as an aside, am I doing iteration and casting over a Node's children incorrectly?

Nake build fails on devel (of 16.05.18)

Nim version devel, of 16.05.18
System - archlinux, xfce 4.12
If any other info needed, please tell
traceback:

GODOT_BIN=/usr/bin/godot nake build
   Warning: Package 'stub' has an incorrect structure. The top level of the package source directory should contain at most one module, named 'stub.nim', but a file named 'mainpanel.nim' was found. This will be an error in the future.
      Hint: If this is the primary source file in the package, rename it to 'stub.nim'. If it's a source file required by the main module, or if it is one of several modules exposed by 'stub', then move it into a 'stub/' subdirectory. If it's a test file or otherwise not required to build the the package 'stub.nim', prevent its installation by adding `skipFiles = @["mainpanel.nim"]` to the .nimble file. See https://github.com/nim-lang/nimble#libraries for more info.
  Verifying dependencies for [email protected]
   Warning: No nimblemeta.json file found in /home/survivor/.nimble/pkgs/qnim-0.1.0
      Info: Dependency on godot@>= 0.7.3 & < 0.8.0 already satisfied
  Verifying dependencies for [email protected]
      Info: Dependency on compiler@>= 0.17.3 already satisfied
  Verifying dependencies for compiler@#head
  Compiling ../src/stub.nim (from package stub) using c backend
Hint: used config file '/home/survivor/.choosenim/toolchains/nim-#devel/config/nim.cfg' [Conf]
Hint: used config file '/home/survivor/g-engine/godot/src/nim.cfg' [Conf]
Hint: used config file '/home/survivor/g-engine/godot/src/config.nims' [Conf]
Hint: system [Processing]
Hint: stub [Processing]
Hint: segfaults [Processing]
Hint: posix [Processing]
Hint: fpscounter [Processing]
Hint: strutils [Processing]
Hint: parseutils [Processing]
Hint: math [Processing]
Hint: algorithm [Processing]
Hint: godot [Processing]
Hint: godotbase [Processing]
Hint: godotinternal [Processing]
Hint: godotinternaltypes [Processing]
Hint: godotarrays [Processing]
Hint: gdnativeapi [Processing]
Hint: godotcoretypes [Processing]
Hint: macros [Processing]
Hint: hashes [Processing]
Hint: godotnodepaths [Processing]
Hint: godotpoolarrays [Processing]
/home/survivor/.nimble/pkgs/godot-0.7.10/internal/godotpoolarrays.nim(112, 16) template/generic instantiation from here
/home/survivor/.nimble/pkgs/godot-0.7.10/internal/godotpoolarrays.nim(94, 11) Error: wrong number of variables
       Tip: 11 messages have been suppressed, use --verbose to show them.
     Error: Execution failed with exit code 1
        ... Command: "/home/survivor/.nimble/bin/nim" c --noNimblePath --path:"/home/survivor/.nimble/pkgs/godot-0.7.10" --path:"/home/survivor/.nimble/pkgs/compiler-#head" "-o:../_dlls/nim_linux_64.so"  "../src/stub.nim"

Looks like issue is mentioned in changelog (line 29-30):

  • The returned tuple of system.instantiationInfo now has a third field
    containing the column of the instantiation.
    I haven't found the godot error function spec, so, for now, the quick way to correct it is modify
    godot-0.7.10/internal/godotpoolarrays.nim(LL94-99) acordingly:
      let (file, line, _) = instantiationInfo()
      getGDNativeAPI().printError(
        cstring"Invalid subarray begin index", cstring"subarray", file, line.cint)
      return
    if actualIdxTo < 0 or actualIdxTo >= ownLen:
      let (file, line, _) = instantiationInfo()

Leveraging types from nim's standard library

I'm curious why you didn't build on top of types from the standard library, like Vector2d from basic2d for example. I'm not proposing it would drastically change anything, but the vector type definition seems to be identical to the standard one, and thus it could be beneficial to have access to nim's functions and overloads on them, and apply whatever Godot defines on top of that starting point. Might be a stupid question stemming from me not being as acquainted with nim as I would like.

Also as a side question, do you frequent the godot or nim IRC rooms or something else of that nature? A lot of the questions I have asked you could be quick conversations on IRC/IM and not pollute the issue tracker :D.

[Suggestion] Show progress of generating godot api bindings

Currently on Windows bindings are not generated very fast (at least for me):

nake build
DETECTED MONITORS: 1
Activated GL 3.3 contextOpenGL ES 3.0 Renderer: GeForce GTX 750/PCIe/SSE2
GLES3: max ubo light: 409
GLES3: max ubo reflections: 455, ubo size: 144
ERROR: No loader found for resource: res://godotapi/api.json
   At: core\io\resource_loader.cpp:223
ERROR: Failed loading scene: res://godotapi/api.json
   At: main\main.cpp:1460
WARNING: ObjectDB::cleanup: ObjectDB Instances still exist!
     At: core\object.cpp:2003

Someone can think that it freezed, but it didn't (because I see new files created in godotapi folder)

Maybe we can add simple progress?

Opening a file doesn't work

It seems to me that this low level call fails:

fileOpenMethodBind.ptrCall(self.godotObject, argsToPassToGodot, ptrCallRet)

calling 'fileExists' with the same path works and at the C++ level the file also must be open to checked if the file exists, see:

/godot/core/os/file_access.cpp

Multithread singletons

I'm trying to access the VisualServer from a thread I created. So I'm using a code like this:

gdobj MyNode of Node:
  var thread: system.Thread[MyNode]
  method ready*() {.gdExport.} =
    createThread[MyNode](thread, threadProc, self)
  
  proc threadProc() {.thread.} =
    var meshRid = visual_server.meshCreate()

When I run the code, I have the following error:

ERROR: : Unhandled Nim exception: D:\Users\Godot\scripts\nim\src\script_lib\map\terrain\hex_terrain.nim(246) threadProc
D:\Users\Godot\scripts\nim\src_godotapi\visual_server.nim(4381) meshCreate
C:\Users\fallo.nimble\pkgs\godot-0.7.20\nim\godotnim.nim(374) getSingleton
C:\Users\fallo.nimble\pkgs\godot-0.7.20\nim\godotnim.nim(300) asNimGodotObject
C:\Users\fallo.nimble\pkgs\godot-0.7.20\nim\godotnim.nim(274) newNimGodotObject
D:\nim-0.20.2\lib\system\assertions.nim(27) failedAssertImpl
D:\nim-0.20.2\lib\system\assertions.nim(20) raiseAssert
D:\nim-0.20.2\lib\system\fatal.nim(39) sysFatal
Error: unhandled exception: C:\Users\fallo.nimble\pkgs\godot-0.7.20\nim\godotnim.nim(274, 9) not classRegistry.isNil [AssertionError]

At: godotnim.nim:908

Apparently when a new thread is created the visual server class is not registered (in the new thread context), and since the singleton is a threadvar, it is nil and can't be used.
Is there a way to solve this?

how use ?

Hi, I would like to use your binding but I have different problems
For example, I would just like to move a sprite on the screen but I don't see the code to do...
Could you make some examples in the repo? I tried to do it like in GdScript but I must be doing something wrong

Using VCC makes Godot crash on Windows 10

Try to use godot-nim-stub on Windows 10, I installed the C++ build tools using the 2019 installer.
It compiles and running the stub in godot works fine too, but recompiling gives me the error that vcc can't compile it because it's locked and then Godot just crashes.
Switching to gcc in config.nims makes it work flawless though.

So is this something VCC <-> Nim related or is my setup of the C++ build tools messed up?
Any downsides in just using GCC?

SIGSEGV: Illegal storage access

Hello!
I'm using godot 3.0.6-stable and using godot-nim-stub as a base project. I wrote very simple script using MeshDataTool:

import godot
import engine, mesh_instance, mesh_data_tool, array_mesh
import strutils

gdobj NoisedMesh of MeshInstance:

  method ready*() =
    print("Noised mesh is ready")

  proc makeSomeNoise*(iterations: int) {.gdExport.} =
    var tool = MeshDataTool.new()
    if tool == nil:
      print("Tool is nil")
      return
    var mesh = self.mesh as ArrayMesh
    if mesh == nil:
      print("Mesh is nil")
      return
    print("Blend shapes:", mesh.getBlendShapeCount())
    print("Surface count:", mesh.getSurfaceCount())
    var err = tool.createFromSurface(mesh, 0)
    print("Error:", err)
    for i in 1..iterations:
        print("Iteration ", i)
    var new_mesh = ArrayMesh.new()
    err = tool.commitToSurface(new_mesh)
    print("Error: ", err)
    self.mesh = new_mesh

When I call function make_some_noise(100) from gdscript the application is failed with this log:

OpenGL ES 3.0 Renderer: NVIDIA GeForce GT 1030 OpenGL Engine
Noised mesh is ready
Blend shapes:0
Surface count:1
Traceback (most recent call last)
godotmacros.nim(569)     methFunc
noisedmesh.nim(26)       makeSomeNoise
mesh_data_tool.nim(76)   createFromSurface
godotinternal.nim(19)    ptrCall
SIGSEGV: Illegal storage access. (Attempt to read from nil?)

I rebuilded nim godotapi for version 3.0.6 but it doesn't help. It seems to be the same as godotapi in current godot-nim-stub.
What can I do to fix that problem?

Godot debug hangs

I am new to Nim and Godot, so please bear with me. Also, note that this code comes from Heartbeast's [GDScript] Godot tutorial.

I was trying to get an FSM from Synthesis working to run a player's animation state machine, although I am running into a problem: the Godot debug hangs on the splashscreen and eats up an increasing amount of memory. The debugger shows no information about the debug process and there are neither errors nor print outputs while it runs. When the self.processAnimation... line is commented out, the program runs perfectly (with no player animations).

Is there a better way to do this? Is this a problem with godot-nim?

Player Nodes

Player
-> Sprite
-> CollisionShape2D
-> AnimationPlayer
-> AnimationTree

player.nim

import godot
import godotapi / [kinematic_body_2d,
                  input,
                  scene_tree,
                  animation_node_state_machine_playback]
import util
import synthesis

const
  MAX_SPEED = 150
  ACCELERATION = 500
  FRICTION = 750
  VECTOR_ZERO = vec2()

type
  # States and Events
  AnimationState = enum
    IDLEING
    MOVING
  AnimationEvent = enum
    STOP
    MOVE

gdobj Player of KinematicBody2D:  # Linter shows error here although compilation succeeds.
  var
    velocity = vec2()

    # Player Animation
    animationTree: AnimationTree
    animationState: AnimationNodeStateMachinePlayback
    animationPlayer: AnimationPlayer

    processAnimation: proc(x: Vector2, y: bool)

  method ready*() =
    # Animation Setup
    self.animationPlayer = (self.getNodeOrNull("AnimationPlayer")) as AnimationPlayer

    self.animationTree = (self.getNodeOrNull("AnimationTree")) as AnimationTree
    self.animationTree.setImpl("active", true.toVariant)

    self.animationState = asObject[AnimationNodeStateMachinePlayback](self.animationTree.getImpl("parameters/playback"))

    # Animation State Machine
    declareAutomaton(animationSM, AnimationState, AnimationEvent)

    setInitialState(animationSM, IDLEING)
    setTerminalState(animationSM, Exit)

    # Event Triggers
    implEvent(animationSM, MOVE):
      direction != VECTOR_ZERO
    implEvent(animationSM, STOP):
      direction == VECTOR_ZERO

    # State Relationships (Transitions)
    # None of the print statements show up in Output
    behavior(animationSM):
      ini: IDLEING
      fin: MOVING
      event: MOVE
      transition:
        self.animationTree.setImpl("parameters/Idle/blend_position", direction.toVariant)
        self.animationTree.setImpl("parameters/Run/blend_position", direction.toVariant)
        self.animationState.travel("Run")
        print("IDLE -> MOVE")
    behavior(animationSM):
      steady: IDLEING
      transition:
        self.animationState.travel("Idle")
        print("Idleing")
    behavior(animationSM):
      ini: MOVING
      fin: IDLEING
      event: STOP
      transition:
        self.animationState.travel("Idle")
    behavior(animationSM):
      steady: MOVING
      transition:
        self.animationTree.setImpl("parameters/Idle/blend_position", direction.toVariant)
        self.animationTree.setImpl("parameters/Run/blend_position", direction.toVariant)
        print("MOVING STEADY")

    # This is probably where the problems come from...
    # The `synthesize` macro spits out a proc that runs the FSM, which can't be
    # used unless it's assigned to a Player-level closure. Unless there's a
    # better way?
    synthesize(animationSM):
      proc processAnimationImpl(direction: Vector2, animationFinished: bool)

    self.processAnimation = processAnimationImpl

  method physicsProcess*(delta: float64) =
    print("Got here")  # Doesn't print

    # Movement
    var inputVector = vec2()

    inputVector.x = getActionStrength("ui_right") - getActionStrength("ui_left")
    inputVector.y = getActionStrength("ui_down") - getActionStrength("ui_up")
    inputVector.normalize

    if inputVector != VECTOR_ZERO:
      self.velocity.moveToward(inputVector * MAX_SPEED, ACCELERATION * delta)
    else:
      self.velocity.moveToward(VECTOR_ZERO, FRICTION * delta)

    self.velocity = self.moveAndSlide(self.velocity)

    # Run the state machine
    self.processAnimation(inputVector, false)  # Linter notes: `physicsProcess` is not GC-safe as it performs an indirect call here

Error: unhandled exception: index out of bounds [IndexError]

Nim version: git hash: 6713e70d756c04dbd54d32feb78ae62eed6bda4e

[david@eb myproject]$ ./nakefile  build
OpenGL ES 3.0 Renderer: Quadro K3000M/PCIe/SSE2
Generating audio_stream_player_2d.nim...
Generating shape_2d.nim...
Generating dynamic_font_data.nim...
Generating light_2d.nim...
Generating primitive_mesh.nim...
Generating shader.nim...
Generating scene_tree_timer.nim...
Generating editor_file_dialog.nim...
Generating packed_scene.nim...
Generating visual_script_function.nim...
Generating animation.nim...
Generating visual_script_sub_call.nim...
Generating video_player.nim...
Generating http_client.nim...
Generating sky.nim...
Generating animation_player.nim...
Generating sprite_base_3d.nim...
Generating polygon_path_finder.nim...
Generating capsule_mesh.nim...
Generating visual_script_constructor.nim...
Generating kinematic_collision.nim...
Generating web_socket_client.nim...
Generating geometry_instance.nim...
Generating groove_joint_2d.nim...
Generating translation_server.nim...
nake.nim(93)             moduleHook
nakelib.nim(252)         runTask
nakefile.nim(29)         :anonymous
nakefile.nim(16)         genGodotApi
godotapigen.nim(957)     genApi
renderer.nim(1442)       renderTree
renderer.nim(635)        gstmts
renderer.nim(546)        gsub
renderer.nim(1254)       gsub
renderer.nim(609)        gsection
renderer.nim(1160)       gsub
renderer.nim(546)        gsub
renderer.nim(1127)       gsub
renderer.nim(546)        gsub
renderer.nim(1167)       gsub
renderer.nim(546)        gsub
renderer.nim(1174)       gsub
renderer.nim(1341)       gsub
renderer.nim(321)        gcoms
renderer.nim(318)        gcom
renderer.nim(226)        putComment
system.nim(2843)         sysFatal
Error: unhandled exception: index out of bounds [IndexError]

Node2d globalPosition should be Vector2

In the generated godotapi, Node2d's globalPosition is a float64 instead of Vector2. I'm not sure where to file this, but in looking through the godot source code everywhere I see get_global_position it is a vector2/point2 type, not a float.

proc globalPosition*(self: Node2D): float64 {.gcsafe, locks: 0.}
proc `globalPosition=`*(self: Node2D; val: float64) {.gcsafe, locks: 0.}

--hotcodereloading:on How to get it working?

How can we enable hotcode reloading with nim? I naively tried putting an extra argument in the nakefile.nim for the stub like so:

direShell(["nimble", "c", "--hotcodereloading:on", ".."/"src"/"stub.nim", "-o:.."/"_dlls"/libFile]

but I get a bunch of errors like:

generated_not_to_break_here(1000281): error C2065: 'setupLocalToScene__gLyBeqUX2Us9boM4Oe9cHZSg': undeclared identifier
generated_not_to_break_here(1000282): warning C4047: '=': 'int' differs in levels of indirection from 'tyProc__XUVGJ9cWq1ACzFb01P8X1GA'
Error: execution of an external compiler program 'vccexe.exe /c --platform:amd64 /nologo -DWIN32_LEAN_AND_MEAN /MD /Zi /FS /Od  /IC:\Users\gr\.choosenim\toolchains\nim-1.2.0\lib /IC:\godot\GodotNimStub\src /FoC:\godot\GodotNimStub\src\.nimcache\windows\amd64\@mstub.nim.c.obj C:\godot\GodotNimStub\src\.nimcache\windows\amd64\@mstub.nim.c' failed with exit code: 2


       Tip: 4 messages have been suppressed, use --verbose to show them.
  Error: Execution failed with exit code 1
     ... Command: "C:\Users\gr\.nimble\bin\nim.exe" c --noNimblePath -d:NimblePkgVersion=0.1.0 --path:"C:\Users\gr\.nimble\pkgs\godot-0.7.27" --path:"C:\Users\gr\.nimble\pkgs\compiler-1.2.0" "--hotcodereloading:on" "-o:..\_dlls\nim_64.dll"  "..\src\stub"

Also, it doesn't seem like I can build with nake while the app is running either.

How to access fields in GDScritp from Nim?

Two people on discord told me get("property_name") works in C++, D, etc, so I am assuming it should work in Nim as well, but it didn't. From my current test project:

In Data.gd (autoloaded as "data")

extends Node

export fov_radius = 42  # export isn't needed here, I just tested this with/without it

Then in a Nim file

let data = self.get_tree().root.get_node("data")
print(data.get_class()) # >>> Node

print("fov_radius: ", data.get("fov_radius")) 
# runtime error: Unhandled Nim exception (NilAccessError): Could not access value because it is nil.

How can I make it work?

(Note: I don't necessarily need this only to access autoloaded scripts, I might want to get access to something else.)

isAction(Just)?(Pressed|Released) don't work

Maybe it's just something I'm doing or not doing, but I cannot get any of the isActionPressed methods to work.

Minimal example:

import godot, node
import input, scene_tree

gdobj Arena of Node2d:
  method process(dt: float64) =
    if isActionJustPressed("ui_cancel"):
      print "quit"
      getTree().quit()

Undeclared identifier errors

So this works:

import godot, node_2d, rich_text_label, line_edit, strformat

gdobj Loony of Node2D:
  var storyText: RichTextLabel
  var textBox: LineEdit
  var prompts = @["Rishi", "lice", "bad", "great", "cabbages"]
  var story = &"Power"

  method ready*() =
    storyText = getNode("Blackboard/StoryText").as(RichTextLabel)
    storyText.text = story

  method onTextEntered*(newText: string) {.base.} =
    storyText = getNode("Blackboard/StoryText").as(RichTextLabel)
    storyText.text = newText
    textBox = getNode("Blackboard/TextBox").as(LineEdit)
    textBox.clear()

  method onButtonPressed*() {.base.} =
    var newText = getNode("Blackboard/TextBox").as(LineEdit).text
    onTextEntered(newText)

As soon as I use the string interpolation feature eg the variable story becomes: var story = &"Once upon a time a {prompts[0]} ate a {prompts[1]} and felt very {prompts[2]}. It was a {prompts[3]} day for {prompts[4]}" it throws the error can't find prompts identifier .

Now the most quirky thing I don't understand if I change the fields section to:

  var
    storyText: RichTextLabel
    textBox: LineEdit
    prompts = @["Rishi", "lice", "bad", "great", "ponies"]
    story = &"Once upon a time a {prompts[0]} ate a {prompts[1]} and felt very {prompts[2]}. It was a {prompts[3]} day for {prompts[4]}"

I get can't find identifier story in the ready method and can't find identifier textBox in the onTextEntered method.
Am I understanding something wrong here about the gdobj fields?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.