Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Zerobrane Live Coding Beginner Question — Gideros Forum

Zerobrane Live Coding Beginner Question

david19801david19801 Member
edited November 2012 in General questions
Hello,

I'm trying to set up Zerobrane for live coding with Gideros player (not mobile player, just IDE player).

I can make Zerobrane show my main.lua code in the Gideros player (just a ball image), but it does not update live when I change the x and y position using the slider system...

Here is my main.lua code (the only file except the gproject file and ball.png):



require("mobdebug").start()

local fruit = Bitmap.new(Texture.new("ball.png"))
stage:addChild(fruit)

function onEnterFrame(event)
fruit:setX(78)
fruit:setY(170)
end

stage:addEventListener(Event.ENTER_FRAME, onEnterFrame)



I have chosen the project->interpreter as Gideros and I am just choosing "run as scratchpad" and nothing else when I run it.

Any idea what is going wrong?

Also, do I need to require any special files when doing live coding? I just have main.lua...

Is the require("mobdebug").start() necessary to do livecoding? I just have main.lua in my folder...do I need a mobdebug file?
+1 -1 (+2 / -0 )Share on Facebook

Comments

  • I haven't tried yet myself, but http://www.giderosmobile.com/forum/discussion/1864/20-minutes-to-awesome has a nice example video which hopefully should help out.
  • MagnusviriMagnusviri Member
    edited November 2012
    You definitely need to require mobdebug as well as sockets. Use the versions that come with the demo code app. It took me awhile to figure out how to do it. You also must run the app in Gideros player, go to ZeroBrane and click on the file you want to edit then select "run as scratchpad". It took me awhile to make sure I was running the correct file. I also restarted the whole thing many times until I figured out the correct sequence of moves.
  • bowerandybowerandy Guru
    edited November 2012
    @david190801, I suspect that the issue that is causing your crash is because you are restarting the debugging session each time the code is changed.

    When you run a file as scratchpad in ZBS, then each time you type a character the whole file is compiled and (if the compile is successful) it is sent to the player to be executed. If you look at my example in Twenty Minutes to Awesome, you'll see that the project is split into more than one file. The require("mobdebug").start() line is in main.lua and this is only ever executed one because it is not the file being used as the scratchpad.

    An alternative, if you just want to use a single file, would be to wrap code that must only execute once in a guard clause:
    local alreadyRun
    if not(alreadyRun) then
        require("mobdebug").start()
        alreadyRun=true
    end
     
    local fruit = Bitmap.new(Texture.new("ball.png"))
    stage:addChild(fruit)
    I hope that helps

    best regards
  • @david190801, "alreadyRun" should probably be a global var in @bowerandy's example to keep the value between runs.

    Something like this should work:
    function Application:clearStage()
      while stage:getNumChildren() > 0 do stage:removeChildAt(1) end
    end
    application:clearStage()
     
    local fruit = Bitmap.new(Texture.new("ball.png"))
    stage:addChild(fruit)
    function onEnterFrame(event)
      fruit:setX(108)
      fruit:setY(153)
    end
     
    if not alreadyRun then
      require("mobdebug").start()
      stage:addEventListener(Event.ENTER_FRAME, function(...) pcall(onEnterFrame, ...) end)
      alreadyRun=true
    end
    This discussion may be useful to see the explanation on why it works this way: http://www.giderosmobile.com/forum/discussion/1427/a-live-repl-like-we-have-in-ruby/p1
  • MagnusviriMagnusviri Member
    edited November 2012
    I am doing a very similar thing with my Gideros downloader.

    http://blog.magnusviri.com/gideros-downloader.html

    Basically instead of having an IDE send the compiled file, my Gideros app actually downloads the desired file(s) repeatedly from a url (in this case, Dropbox). I have to wrap some of the code in a first time block so that it doesn't get executed over and over. Look at the very bottom of the blog post to see an example. It's pretty confusing and so I don't really code like this, I just restart my app.
  • john26john26 Maintainer
    edited November 2012
    These discussions make me think the live coding approach is not very suitable for beginners as there are several "gotchas" which require deep knowledge to circumvent. Just my opinion...
  • @john26, it depends. There are definitely things to keep in mind when developing live-coding-friendly apps, but I think they should be easy to follow and can be roughly summarized as this:

    1. Isolate your initialization code to make it run once; add your addEventListener calls to this initialization code
    2. Use globals for objects you want to keep between restarts as in: fruit = fruit or Bitmap.new(Texture.new("ball.png")) or BhLiveCode = BhLiveCode or Core.class(Sprite)
    3. Wrap callback functions into an anonymous function to allow it to change as in: stage:addEventListener(Event.ENTER_FRAME, function(...) onEnterFrame(...) end)
    4. Use pcall to "protect" from run-time errors in event handlers as in: stage:addEventListener(Event.ENTER_FRAME, function(...) pcall(onEnterFrame, ...) end)

    @bowerandy and @atilim, anything else you want to add?
  • bowerandybowerandy Guru
    edited November 2012
    @john26, @paulclinger, my intention in the future is to create a framework whereby most of these "gotchas" are automatically taken care of so that the beginner doesn't need to be aware of them. For example, I believe the callback wrapping can be done automatically by overriding the addEventListener() method.

    In my Live Coding demo, you probably saw that I had added a RestartRequired button to the screen. I would imagine that something like this would also be a part of the framework. I haven't decided yet what format all this will take but my intention will certainly be to make it more beginner (or child) friendly in future.

    best regards

    Likes: Platypus

    +1 -1 (+1 / -0 )Share on Facebook
  • > my intention will certainly be to make it more beginner (or child) friendly

    @bowerandy, I'm with you 100% on this.

    Likes: Platypus

    +1 -1 (+1 / -0 )Share on Facebook
  • For me it's working on the local host's Gideros player but I can't get it to work on a remote device (android). I tried this,

    require("mobdebug").start("Android's IP")

    but the player windows still opens on the computer and not the phone.

    Any thoughts?
    Thanks.
  • @skaflux, at this time you can only start debugging from ZBS locally. To do it remotely, you need to do the following:

    1. Start the Gideros player player on your device
    2. Add (or modify) 'require("mobdebug").start("PC with ZeroBrane Studio IP")' (not Android's IP)
    3. Start ZBS and start the debugger server ('Projects | Start Debugger Server')
    4. Deploy and run the application from Gideros Studio
    5. You should now see the green arrow in ZBS and can debug as before.

    I remember @boverandy described this process he worked through in one of his comments, but can't find it right now.

    We've also discussed adding a hint for ZBS in the form of:

    require("mobdebug").start("PC with ZeroBrane Studio IP") -- remote IP (in this case Android's IP)

    but it hasn't been implemented yet.

    Likes: skaflux

    +1 -1 (+1 / -0 )Share on Facebook
  • debashishdebashish Member
    edited August 2013
    hi,

    I have a problem here when I am using the scratchpad in ZBS for Android but its not updating the running program.

    I have sincerely followed every step in @boverandy tutorial.

    i.e.,

    1. Start the Gideros player player on your device
    2. Add (or modify) 'require("mobdebug").start("PC with ZeroBrane Studio IP")' (not Android's IP)
    3. Start ZBS and start the debugger server ('Projects | Start Debugger Server')
    4. Deploy and run the application from Gideros Studio
    5. You should now see the green arrow in ZBS and can debug as before.

    Please help!
  • @debashish, the sequence of steps looks correct. Can you try it on this simple example first: http://notebook.kulchenko.com/zerobrane/gideros-live-coding-a-simple-example? Maybe it will give you an idea on what's different in your case...
Sign In or Register to comment.