Howdy, Stranger!

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

Open in codea a new file

in General Posts: 8

Hello, can someone explain me how I can open in the codea-code a new screen that is saved in an other file.
So by example I want to switch from the file Main to a new screen that I called RegisterScreen.
So if someone can explain me how to switch from Main to RegisterScreen
(I don' t mean a new class(file).)

Comments

  • IgnatzIgnatz Mod
    edited June 2015 Posts: 5,396

    Are you asking how you can switch between two screens, eg a menu screen and a playing screen?

    If so, set a variable, eg

    function draw()
        background(50)
        if state=="menu" then
           --draw the menu screen in here
        elseif state=="playing" then
           --draw the playing screen in here
        end
    end
    

    so Codea draws the screen depending on state

  • Posts: 8

    @Ignatz No I mean switching between two files, so that are No class files but two files with different screens and each a setup() and draw() function, I want to switch between the screens that are each in a separate file (in this case, the file Main and RegisterScreen.

  • Posts: 104

    I don't think what you're suggesting is possible (as far as I'm aware, the setup and draw loops for a single app have to be unique and you can't switch from one to another).

    However, you should look into other ways of achieving the same end. @Ignatz has suggested one. Personally I have found this thread on "scenes" and scene management invaluable. It really helped me organise my code.

    http://codea.io/talk/discussion/677/scenemanager

  • edited June 2015 Posts: 8

    Ok thank you all for helping, but why can we create a new empty file (I mean again No .class file) if iT's not possible to use the new file? @epicurus101 @Ignatz

    (I have already an idea how to fix my problem but I wondering about that)

  • Posts: 2,020

    have a look at the physics lab demo project. That has different scenes in different tabs

  • Posts: 104

    @SvCoder it's entirely possible to use the new tab, just not in the way you want to I'm afraid! It's not a new file as such, it's all part of the same code, but different tabs can help organise your code (so that functions which are related all sit in one tab) and it can help you provide different scoping for local variables.

  • Posts: 2,020

    Well... I guess this is perhaps getting into semantics, but tabs could be considered different files (within the same project), with local scoping and so on. If you use a source code manager to send a project to GitHub or BitBucket, each tab is a separate .lua file.

    @SvCoder you could have lots of setup and draw functions, but you'd have to give them different names, eg

    --# Test1
    Test1={} --just a table, not a class
    
    function Test1.setup()
        -- set up test 1
    end
    
    function Test1.draw()
        --draw test 1
    end
    
  • Jmv38Jmv38 Mod
    Posts: 3,295

    tabs actually are dirrent files in Codea internal disk.

  • Posts: 104

    Live and learn!

Sign In or Register to comment.