I am having trouble using the touch function from classes other than the main one. For example, if I try calling the function inside the main class it doesn’t work, and I can’t call the function inside the class where it is needed, or otherwise is presents me with an error. Can anyone help me out on a possible solution as I never really got the hang of this, and have been putting this off for some time. Thanks!
Something like this
function setup()
c=Car()
end
function touched(touch)
c:touched(touch)
end
Car = class()
function Car:touched(touch)
print(touch.x)
end
Edit: i just posted a second after @Kjell
@DarrellBro I’m sorry, I just can’t stand the sight of this. It’s you’re, not your.
@YoloSwag I’m not sure what you’ve already done, so I’m just giving the basics here.
If you have defined MyClass = class()
and a function MyClass:touched(touch)
, you can call the touch function like this:
function setup()
obj = MyClass()
end
function touched(touch)
obj:touched(touch)
end
Make sure you pass the touch
userdata to the function every time you call it.
Thank you both. This helps a lot!