Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Classes and blank files

edited April 2012 in Questions Posts: 7

Hey, I'm new to Codea and I was wondering what are classes and blank files for? I know I can put more code on them but how would I be able to "link" that code with my main code and use it then. Are there any sites for tips and tutorials such as these? ( I checked the wiki, but most of the links are broken)

Thanks in advance.

Comments

  • SimeonSimeon Admin Mod
    Posts: 5,054

    Classes are identical to blank files except they include a basic class template using the name that you specify. This just saves you some typing if you intend to make a class.

    All the code is executed when you press play — so your classes will be available to all your other files.

    For example, if you create a class called MyClass, you can create an instance in your setup() function as follows:

    function setup()
        foo = MyClass()
    
        -- Do things with foo... 
    end
    
    function draw()
        foo:draw()
    end
    
  • Posts: 7

    @Simeon So if I have a different function setup in MyClass but in the main file I write foo = MyClass() it will run that setup? (same goes for draw?)

  • Posts: 1,255

    foo = MyClass() would make foo an instance of MyClass and run MyClass:init().

    If you used foo:draw() after that, it would run the code in MyClass:draw()

Sign In or Register to comment.