Howdy, Stranger!

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

Game for my daughter: charlotte's choices

edited April 2014 in Code Sharing Posts: 557

Hi,

I'm always really impressed at how small people can make their programs!

I want to post my code and see if anyone can tell me if there's a way to make it as impressively compact as others I've seen here.

It's a very simple adventure game that my daughter designed. I could just cut and paste it but it has a lot of custom art, and I don't know how to share those things.

I gather this is what codea community will be for but it doesn't seem totally ready yet.

What's the best way to do this?

Tagged:

Comments

  • BriarfoxBriarfox Mod
    Posts: 1,542

    You could put the assets in dropbox and load them with http.request before the program loads.

  • Posts: 557

    How do you do that?

  • edited April 2014 Posts: 2,042

    @UberGoober, basically you check if the image exists and if not you download and save it.

    I wrote a class to do this. You can get the code here: http://twolivesleft.com/Codea/CC/alpha/index.php?v=1395

    It includes a Main class showing how to use the Loader class and a Data tab showing how to feed it the names and URLs of images to get.

    (note: this class was specially designed to work with the URLs you get from 'Copy Link' on a shared Dropbox image. If you use a different site like imgur, I have a different class for that :) )

  • Posts: 557

    @JakAttack, I can't get that working.

    I tried this, taken directly from the Codea in-app documentation, in my setup function:

    logoImage = nil
    didGetImage = function( theImage, status, head )
        logoImage = theImage
    end
    http.request( 'https://www.dropbox.com/s/r6wg8mn555l54n8/maxresdefault.jpg',
                  didGetImage )
    saveImage('Documents:Victory',logoImage)
    

    ...and it doesn't work. Shouldn't it?

  • Posts: 1,976

    Dropbox is weird like that. You did your code right.

    What Dropbox does when you access an image's link is that it returns an HTML page with a preview, share links, and a download button.

    You can get Dropbox to work right by opening the Dropbox page for you image, and copying the download link, not the page link, by long pressing the download button and selecting "copy."

    I believe you can also make it work by using the normal Dropbox link, but changing the website to dl.dropboxusercontent.com instead of dropbox.com

  • Posts: 557

    @SkyTheCoder thanks! I'll try that!

  • Posts: 557

    @SkyTheCoder I still can't make that work. Just... Nothing. Does anybody have this working?

  • Posts: 77

    @UberGoober yes next works for me

    -- Request an image
    function setup()
        logoImage = nil
           -- Request some data                         
        http.request( 'https://dl.dropboxusercontent.com/s/r6wg8mn555l54n8/maxresdefault.jpg',
                  didGetImage )
    end
    
    -- Our callback function
    function didGetImage( theImage, status, head )
        logoImage = theImage
        saveImage("Documents:Victory",logoImage)
    end
    
    function draw()
        background(20,20,40)
        if logoImage ~= nil then
            sprite(logoImage, WIDTH/2,HEIGHT/2)
        end
    end
    
  • Posts: 557

    Ah, I see: it does work. Thank you. Hope you liked the Kevin Dillon!

    My problem was that I wasn't drawing the image. The code successfully draws the image.

    I was expecting the code to save the image.

    If this code doesn't do that, how is that done?

  • Posts: 2,042

    The line saveImage saves the image

  • Posts: 557

    But it doesn't for me. The image shows on the screen fine, but when I go to look in my documents folder it isn't there. Have you checked your documents folder after running this?

  • edited April 2014 Posts: 77

    @UberGoober With the Code above the image is saved as Victory.png in my Documents folder

  • edited April 2014 Posts: 2,042

    @UberGoober, @matox is correct. It works.

  • Posts: 557

    Geezow, guys! What could I be doing wrong?

    No fair it working for you and not me!
    :(( :D

    Below is my entire actual main tab. I'm including everything, even the commented-out stuff, in case any of it happens to contain what I'm missing.

    What am I doing wrong???

    -- Main
    -- A Day of Choices
    
    --basic settings
    supportedOrientations(LANDSCAPE_ANY)
    displayMode(FULLSCREEN)
    icon = readImage("Documents:Choices Icon")
    saveImage("Project:Icon", icon)
    
    -- Our callback function
    function didGetImage( theImage, status, head )
        logoImage = theImage
        saveImage("Documents:Victory",logoImage)
    end
    
    --[[function draw()
        background(20,20,40)
        if logoImage ~= nil then
            sprite(logoImage, WIDTH/2,HEIGHT/2)
        end
    end ]]
    
    function setup()
        logoImage = nil
           -- Request some data                         
        http.request( 'https://dl.dropboxusercontent.com/s/r6wg8mn555l54n8/maxresdefault.jpg',
                  didGetImage )
        mainObject = MainObject()
        -- used as needed to position things on screen
        parameter.number("positionX",0,WIDTH)
        parameter.number("positionY",0,HEIGHT)
        parameter.number("widthX",0,WIDTH)
        parameter.number("heightY",0,HEIGHT)
    end
    
    function draw()
        mainObject:draw()
        -- modify and uncomment the following to use it for positioning
        -- sprite("Documents:choices cup big", positionX, positionY)
        if logoImage ~= nil then
            sprite(logoImage, WIDTH/2,HEIGHT/2)
            end
    end
    
    function touched(touch)
        mainObject:touched(touch)
    end
    
  • Posts: 1,976

    Odd...that code isn't saving any images for me, either.

    Perhaps it's because it's a .jpg file? Maybe you should try .png.

  • Posts: 557

    @SkyTheCoder
    Butbutbut--the code that everybody says works is using a .jpg too.

  • dave1707dave1707 Mod
    Posts: 7,923

    I tried the code above, and it saved an image named Victory in the Documents folder. The size of the image was 1280x720. I had to comment out some code to get it to run, but it ran OK after that.

  • Posts: 557

    I terminated the app and re-launched it and then the image was there. I gather none of you had to do that?

  • Posts: 1,976

    Well, I figured out why it wasn't saving for me. Not enough space. My storage has been dangerously low the past few days, I have to get around to backing up and deleting a bunch of apps and photos again.

  • Posts: 557

    @SkyTheCoder wow--that was my issue too!

    Thanks you guys. You've been great.

  • edited May 2014 Posts: 3

    I tweaked the code a little bit and I think it works now. I hope this helps.


    -- Main -- A Day of Choices --basic settings supportedOrientations(LANDSCAPE_ANY) displayMode(FULLSCREEN) icon = readImage("Documents:Choices Icon") saveImage("Project:Icon", icon) -- Our callback function function didGetImage( theImage, status, head ) logoImage = theImage saveImage("Documents:Victory",logoImage) end --[[function draw() background(20,20,40) if logoImage ~= nil then sprite(logoImage, WIDTH/2,HEIGHT/2) end end ]] function setup() logoImage = nil -- Request some data http.request( 'https://dl.dropboxusercontent.com/s/r6wg8mn555l54n8/maxresdefault.jpg', didGetImage ) -- used as needed to position things on screen parameter.number("positionX",0,WIDTH) parameter.number("positionY",0,HEIGHT) parameter.number("widthX",0,WIDTH) parameter.number("heightY",0,HEIGHT) end function draw() -- modify and uncomment the following to use it for positioning -- sprite("Documents:choices cup big", positionX, positionY) if logoImage ~= nil then sprite(logoImage, WIDTH/2,HEIGHT/2) end end function touched(touch) end
  • dave1707dave1707 Mod
    Posts: 7,923

    @App_Maker I added the three ~ before and after your code to format it correctly.

Sign In or Register to comment.