1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

Seperated Classes

Discussion in 'Development' started by Remarkabless, Dec 10, 2017.

  1. Remarkabless

    Remarkabless Slime

    Messages:
    83
    GitHub:
    Remakem
    how can I use a function from a diffrent class? Im new to seperating classes, I can seperate classes already but how can I use a function from a diffrent class.
     
  2. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    you need to get an instance of the class and call a function to that like ($class = new MyClass())->dosmth()
    or do it staticly if it's static MyClass::doSmthStatic()
     
  3. Remarkabless

    Remarkabless Slime

    Messages:
    83
    GitHub:
    Remakem
    Think you can show me a quick example? I wanna use the function on my plugin called “Interact” from my class called “EventListener” how could i do that? If you could please give me an example?
     
  4. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    add a argument on construct to grab your main class
    and save it in a property
    also add an argument to the newclass command giving it your own class
    access it by using the property you had saved the main class to
     
  5. Kyd

    Kyd Zombie Pigman

    Messages:
    678
    GitHub:
    boi1216
    I think you should ask on stackoverflow for this :D.. This really is not related to pmmp and on stackoverflow you have better chance to get help if you still don't understand it.
     
  6. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    Why do you even want to separate the classes if you don't know how to make them work together?
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.