MrKris1224

Problem with keyboard steering in game

29 posts in this topic

#1 ·  Posted (edited)

Hi, I making game on own graphical engine (using GDI+) and i have some problem with keyboard steering, I using _IsPressed function. The problem is _IsPressed detect keys only when i move my mouse. When I don't moving mouse _ispressed don't works...

I have function (In engine) called _GetKey - it return when player press key listed in array

- removed code-

What's wrong with my function?

I using it in main game loop:
 

While GUIGetMsg() <> $GUI_EVENT_CLOSE ; Main game loop
    PlayerMove() ; Player keyboard steering
    MouseControl() ; Mouse stering
    
    ;(...)
    
    Sleep(5)
WEnd

;(...)

Func PlayerMove()
    Local $cKey = _GetKey(5)
    
    ;(...)
    
    Switch $cKey
        Case "w"
            If MapOffset(0, -1) Then
                $oOffset.Y = $io1
                $oOffset.Direction = $io1
            EndIf
        Case "s"
            If MapOffset(0, 1) Then
                $oOffset.Y = $io2
                $oOffset.Direction = $io2
            EndIf
        Case "a"
            If MapOffset(-1, 0) Then
                $oOffset.X = $io1
                $oOffset.Direction = $io1
            EndIf
        Case "d"
            If MapOffset(1, 0) Then
                $oOffset.X = $io2
                $oOffset.Direction = $io2
            EndIf
    EndSwitch
EndFunc

And only when i move my mouse keys are detected. What is that? Bug or something? I'm using Windows 8.1

(In codes i write ";(...)" there are other game functions but not important)

Edited by Jos

Share this post


Link to post
Share on other sites



#2 ·  Posted

what is $io1 and $io2, they could be your problem?

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

It's value how much script adding to offset (smooth moving) it isn't important. I can just directlu place $oPlayer.posX += without offset.

You know. $io1 and $io2 its value 12/-12 script adding 12 or -12 pixels to offset when it reach 48 or -48 (block in game size in pixels) then player position is changed. But for now there is problem in _GetKey() or _ispressed i don't know...

 

$cKey = _GetKey(5)
ToolTip($cKey, 0, 0)

Tooltip shows key only when i moving mouse and press key at the same time. When i dont move mouse tooltip shows nothing ( "" From _GetKey() )

Edited by MrKris1224

Share this post


Link to post
Share on other sites

#4 ·  Posted

Maybe look at WM_KEYDOWN and WM_MOUSEMOVE instead of using _IsPressed to detect when keys are pressed or the mouse is moved.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

$aChrs = StringSplit("0:1:2:3:4:5:6:7:8:9:a:b:c:d:e:f:g:h:i:j:k:l:m:n:o:p:q:r:s:t:u:v:w:x:y:z", ":"), _

You have a syntax error on this line I think it should be 

$aChrs = StringSplit("0:1:2:3:4:5:6:7:8:9:a:b:c:d:e:f:g:h:i:j:k:l:m:n:o:p:q:r:s:t:u:v:w:x:y:z", ":")

unless there is some purpous for the , _ at the end of that line?

Edited by TwistedXion

Share this post


Link to post
Share on other sites

#6 ·  Posted

keybaord hook? I tried but it's slower for me. I tried gui accelerators and it's fine but accelerators have anoying delay betwen key detects

Share this post


Link to post
Share on other sites

#7 ·  Posted

1 minute ago, TwistedXion said:

$aChrs = StringSplit("0:1:2:3:4:5:6:7:8:9:a:b:c:d:e:f:g:h:i:j:k:l:m:n:o:p:q:r:s:t:u:v:w:x:y:z", ":"), _

You have a syntax error on this line I think it should be 

$aChrs = StringSplit("0:1:2:3:4:5:6:7:8:9:a:b:c:d:e:f:g:h:i:j:k:l:m:n:o:p:q:r:s:t:u:v:w:x:y:z", ":")

unless there is some purpous for the , _ at the end of that line?

It isn't syntax error check that:

 

Global $variable = 1, $var = 2, _
$varrrr = 3, _
$variableee = 4

It working normaly

Share this post


Link to post
Share on other sites

#8 ·  Posted

Capture.PNG

When I run SyntaxCheck prod 

Share this post


Link to post
Share on other sites

#9 ·  Posted

1 minute ago, TwistedXion said:

Capture.PNG

When I run SyntaxCheck prod 

Instert two lines in code ;)
 

$aChrs = StringSplit("0:1:2:3:4:5:6:7:8:9:a:b:c:d:e:f:g:h:i:j:k:l:m:n:o:p:q:r:s:t:u:v:w:x:y:z", ":"), _
$aDecs = StringSplit("30:31:32:33:34:35:36:37:38:39:41:42:43:44:45:46:47:48:49:4A:4B:4C:4D:4E:4F:50:51:52:53:54:55:56:57:58:59:5A", ":")

 

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

47 minutes ago, Jos said:

It still is a syntax error on line1!  

Jos

Ohh... Really? I think NO.

 

Edited by Jos

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

 

I still get the error. Just try taking the ,_ off and see if it works if not there is no harm

Edited by Jos

Share this post


Link to post
Share on other sites

#13 ·  Posted

Oh yes there is as the comma and _ (line continuation) do not surve a purpose and is flagged as such by au3check. ;)

Jos


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

43 minutes ago, TwistedXion said:

 

I still get the error. Just try taking the ,_ off and see if it works if not there is no harm

Maybe different autoit version? I have 3.3.14.2

 And you ahve more errors because you dont have other code functions ;)

 

Edited by Jos

Share this post


Link to post
Share on other sites

#15 ·  Posted (edited)

3 minutes ago, MrKris1224 said:

Ohh... Really? I think NO.

Are you using the full  AutoIt, with SciTE?

As TwistedXion shows you above, you are incorrect. In the future, when someone with more experience on the forum, and in fact someone who has done a lot to drive the language forward, offers a suggestion you don't understand - ask for clarification rather than assuming you know what you're talking about.

Edited by JLogan3o13

√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

#17 ·  Posted

2 minutes ago, JLogan3o13 said:

Are you using the full  AutoIt, with SciTE?

As TwistedXion shows you above, you are incorrect. In the future, when someone with more experience on the forum, and in fact someone who has done a lot to drive the language forward, offers a suggestion you don't understand - ask for clarification rather than assuming you know what you're talking about.

Yes, i have au3 + scite
 

 

2 minutes ago, Jos said:

3-1   I guess we win?

propably, but it's offtop...

Share this post


Link to post
Share on other sites

#18 ·  Posted (edited)

6 minutes ago, MrKris1224 said:

Maybe different autoit version? I have 3.3.14.2

 And you ahve more errors because you dont have other code functions ;)

 

@MrKris1224 yes I pointed that out and no I'm using the most up to date version of autoit with  SciTE4AutoIt3.exe

Edited by TwistedXion

Share this post


Link to post
Share on other sites

#19 ·  Posted

Then when you run CTRL + F5 it should have flagged all of those issues as it did for others. At the very least, having a continuation character at the end of a line, with no continuation, is precisely what Jos was trying to point out to you.


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

#20 ·  Posted (edited)

The issue is simply...  it is valid when you add the line above it as well! not just those 2 lines. ;)

Jos

ps. my last (on topic) post here . 

but it's offtop...

Edited by Jos

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.