Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8171329
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T21:25:44+00:00 2026-06-06T21:25:44+00:00

I am trying to use functions of another class in my main.lua. I wrote

  • 0

I am trying to use functions of another class in my main.lua. I wrote some code according to my research but it’s not working properly. Can you help me out? Thanks.

fish.lua code:

function class()
  local cls = {}
  cls.__index = cls
  return setmetatable(cls, {__call = function (c, ...)
      instance = setmetatable({}, cls)
      if cls.__init then
          cls.__init(instance, ...)
      end
      return instance
  end})
end


 Fish= class()

 function Fish:listen(event)
  if phase =="began" then
          print("hi")
  end
 end

function Fish:__init(image)
    self.image=display.newImage(image,30,30)
    self.image: addEventListener("touch",self.listen)
end

main.lua code:

  require  "fish"

  originalImage="fish.small.red.png"
  differentImage="fish.small.blue.png"

  local fishImage=Fish(originalImage)

It displays the image but does not work(prints “hi” ) when it is touched.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T21:25:46+00:00Added an answer on June 6, 2026 at 9:25 pm

    A couple of problems:

    Change function Fish:listen(event) to function Fish.listen(event)

    and if phase =="began" then should be if event.phase =="began" then

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to use some of the functions that are in the /lib/libproc-3.2.6.so library
I'm trying to use a Class_B function in one of Class_A's functions. But a
I'm trying to use Android Application class (MyApplication.java) for storing data in some ArrayLists
I have code like: <div class=a>Main</div> <div class=b>1</div> <div class=b>2</div> <div class=b>3</div> <div class=a>Another</div>
I was trying use a set of filter functions to run the appropriate routine,
I'm trying to use the function XLookupString . According to the documentation , it
I need some help in bison grammar construction. From my another question: I'm trying
I'm trying to use QSystemTrayIcon to display a message after application initialization. My main
I'm trying to write my own logging class and use it as a stream:
i'm trying to follow DRY and i've got some functions i have to reuse.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.