Jump to content

if window:KeyDown(Key.D) Don't registry keys


TheKkubas
 Share

Recommended Posts

Hi. i'm new to Leadwerks and I started scrpiting in lua. When i try to make basic controller i discovered that bug (or my mistake). Here is one of scripts which i (try to) make.

Script.player = "" --entity "Player"
function Script:Start()

end
function Script:Update()
if window:KeyDown(Key.D) then
print("D Pressed")
right()
end
end
function Script:right()
ppos = self.player:GetPosition()
self.player:SetPosition(ppos+Vec3(3,0,0))
end

When it launched i didn't get any console replys about pressed D and my character didn't move.

At the end sorry for my English. That text could have errors.

Link to comment
Share on other sites

Hi sorry if i am wrong but isnt it "KEY_D" with underscore ? (not the dot .)

No that was how keys were defined in LE2.

 

As for the OP's issues:

- the function is 'Script:UpdateWorld()' not 'Script:Update()'

- the command to print in the LE log is 'System:Print()' not 'print()'

- the function is 'right()' not 'Script:right()' or vice versa

- need to pass the 'self.player' to the 'right()' function if used instead of 'Script:right()' function

 

example lua code:

Script.player = "" --entity "player"

function Script:Start()

 

end

 

function Script:UpdateWorld()

window = Window:GetCurrent()

if window:KeyHit(Key.D) then

System:Print("D Pressed")

right(self.player)

end

end

 

function right(player)

ppos = player:GetPosition()

player:SetPosition(ppos+Vec3(3,0,0))

end

Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590

LE / 3DWS / BMX / Hexagon

macklebee's channel

Link to comment
Share on other sites

No that was how keys were defined in LE2.

 

As for the OP's issues:

- the function is 'Script:UpdateWorld()' not 'Script:Update()'

- the command to print in the LE log is 'System:Print()' not 'print()'

- the function is 'right()' not 'Script:right()' or vice versa

- need to pass the 'self.player' to the 'right()' function if used instead of 'Script:right()' function

 

example lua code:

Script.player = "" --entity "player"

function Script:Start()

 

end

 

function Script:UpdateWorld()

window = Window:GetCurrent()

if window:KeyHit(Key.D) then

System:Print("D Pressed")

right(self.player)

end

end

 

function right(player)

ppos = player:GetPosition()

player:SetPosition(ppos+Vec3(3,0,0))

end

Thank you very much. Script worked but i must fix some bugs (I can do it alone).

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...