Game for my daughter: charlotte's choices

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?

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

How do you do that?

@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 :slight_smile: )

@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?

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

@SkyTheCoder thanks! I’ll try that!

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

@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

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?

The line saveImage saves the image

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?

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

@UberGoober, @matox is correct. It works.

Geezow, guys! What could I be doing wrong?

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

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

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.

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

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.

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

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.