Howdy, Stranger!

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

Simple clicker game

edited December 2015 in Code Sharing Posts: 2
function setup()
    x=0
    print("Taps:" , x)
    function draw()
        text("TAP!!!", WIDTH/2,HEIGHT/2)
        fontSize(200)
    fill(0, 200, 255, 255)
        saveLocalData("save",x)
        function touched(touch)
            if touch.state==BEGAN then
                readLocalData("save",x)
                x=x+1
                text(math.tointeger(x),WIDTH/2,300)
                print("Taps:" , x)
            end
        end
        end
end

Comments

  • dave1707dave1707 Mod
    Posts: 10,053

    @MonsterJace Apparently you didn't learn anything from my response to your first program in the discussion Fight The Boy. In that program you nested the functions draw() and touched() in the function setup() just as you're doing here. You'll never be able to write anything worthwhile if you keep writing code like this. Again, here is your program with the proper way to use the functions setup(), draw(), and touched(touch). I suggest you look at the link Wiki at the top of this page that will give you all the information you need to learn Codea.

    function setup()
        fontSize(200)
        fill(0, 200, 255, 255)
        x=readLocalData("save") or 0
    end
    
    function draw()
        background(0)
        text("TAP!!!", WIDTH/2,HEIGHT/2)
        text(math.tointeger(x),WIDTH/2,300)
    end
    
    function touched(touch)
        if touch.state==BEGAN then
            x=x+1
            saveLocalData("save",x)
        end
    end
    
  • dave1707dave1707 Mod
    Posts: 10,053

    @MonsterJace Just in case you don't understand what's happening, here an explanation. The function setup() gets run one time when the program starts. This is where you put code that needs to run one time, usually initializing variables with their starting values. The function draw() runs 60 times per second as long as your program is running. This is where you add code that updates what you see on the screen. It's like watching TV, but you're in control of what shows. The function touched(touch) gets executed whenever you touch the screen. Information about that touch is saved in the variable touch or whatever name you put in the (). Information such as the x and y position, how many time you touched the screen, the previous x and y positions, and other information you can use. By reading the information you find in the Wiki link, you'll understand this and much more.

  • KaiKai
    Posts: 66

    Hey @MonsterJace, I am developing my own clicker game call "Pizza Clicker". I do understand ther is an online one but I began development before I noticed this. Anyways, if you want to swing by my " Pizza Clicker " code and it is still open for sugestions!

  • KaiKai
    Posts: 66

    My Pizza Clicker is now closed, It refused to post correctly so disregard my last post

Sign In or Register to comment.