Jump to content

Problem with keyboard steering in game


Recommended Posts

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

$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
Link to comment
Share on other sites

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

Link to comment
Share on other sites

  • Developers
1 minute ago, MrKris1224 said:

Instert two lines in code ;)

It still is a syntax error on line1!  

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • Developers

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

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

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
Link to comment
Share on other sites

  • Moderators
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

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

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...

Link to comment
Share on other sites

  • Moderators

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.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

  • Developers

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

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • Jos locked this topic
Guest
This topic is now closed to further replies.
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...