Results 1 to 9 of 9

Thread: Weird error

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Thanks again. The program is working now, but now I'm trying to implement the input handeling and FPC acts up again.
    The code is the following:
    Code:
    pressedkeys_: array of boolean;  
    
    [...]
    
    procedure input.keydownevent(event:psdl_event);
    begin
        pressedkeys_[event^.key.keysym.scancode] := true;
    end;
    
    [...]
    
    function input.waskeypressed(key:psdl_keycode): boolean;
    var
        event: integer;
    begin
        event := key^.keysym.sym;
        waskeypressed := pressedkeys_[event];
    end;
    and the part in the game loop:
    Code:
            while sdl_pollevent(@e) <> 0 do
            begin
                case e^.type_ of
                    sdl_keydown: input_.keydownEvent(e);
                end;
                if input_.waskeypressed(e) = sdlk_escape then running := false;
            end;
    The "event := key^.keysym.sym;" part in input.waskeypressed gives me "Error: Illegal qualifier". It's probably a very trivial mistake on my part, but I can't really figure it out on my own.

    Thanks again in advance for any help.

  2. #2
    The most likely problem is that you are trying to acces elements from dynamic array with no pre set lenght which means it has the lenght of 0 elements. In Delphi this would result in "Out of bonds" error but I'm not sure what error FPC would create.

    Anywhay instead of trying to duplicate C++ method of imput hndling why don't you use one from Pascal based SDL demos.
    It is not always good to directly translate source code from one programming language to another becouse not all programming languages alow using same aproaches.

  3. #3
    Thanks for your answer. I took a quick look at how hedgewars handles its input. Unfortunately, even if I set the array to [0..65536], like they do in hedgewars, the error message remains the same.
    Last edited by much.love; 24-03-2014 at 12:13 AM.

  4. #4
    array size should depend on enum range
    and if key^.keysym.sym is an integer enum or sth then you can typecast it like this: event := integer(key^.keysym.sym);

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •