Hello, I am trying something that works in C but does not work in Nim and I can't figure it out.
bool HandleEvent(SDL_Event *Event)
{
bool ShouldQuit = false;
switch(Event->type)
{
case SDL_QUIT:
{
printf("SDL_QUIT\n");
ShouldQuit = true;
} break;
case SDL_KEYDOWN:
case SDL_KEYUP:
{
SDL_Keycode KeyCode = Event->key.keysym.sym;
auto kState = Event->key.state; // kState = 1 when key is pressed
...
proc handleEvent(event: Event, newKbController: ptr game_controller_input) : bool =
case event.kind:
of QuitEvent:
echo "SDL QUIT"
result = true
of KEYDOWN:
discard
of KEYUP:
var
state = event.key.state // kState = 0 always
...
Why is this event always returning 0 in Nim while in C it returns 1 when the key is pressed?
I even made a custom function in SDL2.dll called SDL_GetEventKeyState(SDL_Event* event) and tried it both in C and Nim and I got the same result.
Am I missing something with Nim?
I'm gonna keep ivestigating, I'm pretty sure I messed something up, but just wanted to share in case i was missing something.
Thank you for your reply, I'll look into it.
Oh hey now that fixed it!
Thank you so much Vladar! I wonder why it doesn't do the same thing as C. I'll look more into the semantics.
By the way, I was trying your sdl2 package's example project and it was leaking memory. Someone else tested it on the discord server and confirmed it.
I don't know if we may be doing something wrong.
Thanks again!
I wonder why it doesn't do the same thing as C.
Because C's switch statement is fall-through, and Nim's one is more secure
example project and it was leaking memory
It might do such thing, the memory management wasn't on my list of priorities for these examples.
If you find the bug, feel free to submit the issue (or better yet, a fix =)).
Also, you might try to play with garbage collectors (see --gc flag).
Thanks for the info, the lesson and the help!
I'll give it a whirl ; )