2DWorlds Forums
Car Driving Problem - Printable Version

+- 2DWorlds Forums (http://2dworlds.buildism.net/forum)
+-- Forum: 2DWorlds (http://2dworlds.buildism.net/forum/forumdisplay.php?fid=4)
+--- Forum: Scripting (http://2dworlds.buildism.net/forum/forumdisplay.php?fid=13)
+--- Thread: Car Driving Problem (/showthread.php?tid=7823)



Car Driving Problem - willnsam - 08-07-2011

I'm trying to make a car that drives left when you hit the left button. Every time I run this script, it says "keyDown is not a property, function, or child of Hinge." Can someone please tell me what I'm doing wrong?

function keydown (LeftArrow)
if keydown then script.Parent.Motorspeed = -5.0
end
end
link(script.Parent.keyDown, keydown)


RE: Car Driving Problem - Qwertygiy - 08-07-2011

KeyDown is only a function of a Tool, and you need to specify which key as a string or byte code. Which is pretty complicated stuff. I might get back to you with a more detailed answer soon


RE: Car Driving Problem - willnsam - 08-07-2011

I see. So I'd basically have to make a tool for this to work.
Actually, that would work better, probably.
But is LeftArrow a legitimate command? I wasn't sure what it would be called.


RE: Car Driving Problem - Qwertygiy - 08-07-2011

It would be something like

[lua]

function keypressed(key)
if key == string.char(019) then
--dostuff
end end

link(script.Parent.KeyDown, keypressed)

[/lua]

But I've had issues with byte codes not working...

Personally, I think that using WASD would be easier than trying to use the arrow keys.


RE: Car Driving Problem - willnsam - 08-07-2011

Yeah, that makes sense. Thanks for the code!