Jump to content

How to check if a key is down in Lua?


ddabrahim
 Share

Recommended Posts

Hi, Sorry for the noob question but I really have no idea what am I doing wrong.

 

I would like to check Inside an object Lua script If a specified Key is pressed then play a specified animation of the object but I always get "then" expected near "(" or "("expectd near ' or argument expected near "(" error message and I have no idea what am I doing wrong. I was looking for the answer in the documentation and in other Lua scripts but I just can't get it to work.

 

This is the code I'm using

 

function Script:UpdateWorld()

if window:KeyDown(Key.W) then
self.entity:SetAnimationFrame(Time:GetCurrent()/50.0,1,self.walk)
end

end

 

Also tried many other ways such as

 

KeyDown(Key.W)
window:KeyDown(Key:W)
Window:KeyDown(Key:W)
KeyDown(Key:W) == true

 

But nothing works wacko.png

 

Also tried using while loop instead of if statement but no luck.

 

I was also watching the Lua script video tutorials on youtube but it using Leadwerks v2.3 and looks like scripting worked differently in that version as even that way I can't get it to work.

 

I'm appreciate any help.

Link to comment
Share on other sites

If inside an entity script you can do:

 

App.window:KeyDown(Key.A)

 

If inside App.lua

 

self.window:KeyDown(Key.a)

 

You were so close with many variations that you had smile.png

 

 

If you want to get caught up quickly on Lua for LE you can schedule some 1 on 1 training via the link in my sig. Each 1 hour session is only $10 and I go through all of this stuff. I explain all of this stuff and you'll understand Lua for LE at a more lower level and why these things are the way they are.

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