Howdy, Stranger!

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

Why is the rectangle not going past the words?

edited October 2013 in General Posts: 577

For some reason when I was making a timer, the rectangle, which shows your progress, stopped going pass the words, does anyone know why?

--The name of the project must match your Codea project name if dependencies are used. 
--Project: Hacker
--Version: Alpha 2.5
--Comments:

-- Hacker

-- Use this function to perform your initial setup
displayMode(FULLSCREEN)
function setup()
    hacked = ""
    progress = 1
    progress2 = 1
    level = 1
    writestage = 1
    write = nil
    level1 = {"struct", "group.info", "init.groups", "!", ".usage", "!", "atomatic.init(2)", "end", "if", "ddos.sur", "then", "init.groups", "!", "nil", "end", 

     "struct", "sprint.IP", "caller.back", "return", "!", "blockage(7)", "end", "if", "sprint.IP", "and", "caller.back", ".!", ".blockage(return)", "then", "sprint.IP", "!", "LAN"}

end

-- This function gets called once every frame
function draw()

    if writestage ~= #level1 + 1 then
     write = keyboardBuffer()
    -- This sets a dark background color 
    background(27, 27, 27, 255)
    fill(44, 100, 31, 255)
    fontSize(25)
    if level == 1 then
    text("struct group.info init.groups ! .usage ! atomatic.init(2) end if ddos.sur\n then init.groups ! nil end", 380, HEIGHT - 40)
    elseif level == 2 then text("struct sprint.IP caller.back return ! .blockage(7) end if sprint.IP and\n caller.back .! .blockage(return) then sprint.IP ! LAN", 368, HEIGHT -40)
    end
    write = keyboardBuffer() noStroke()
    fill(40, 53, 27, 112)
    rect(0, HEIGHT - 40, progress, 30)
    rect(5, HEIGHT - 75, progress2, 30)
   if write ~= nil then 
    fill(52, 86, 31, 255)
   text(write, WIDTH/2, HEIGHT/2)
end

text(hacked, WIDTH/2, HEIGHT/2 + 100)
fontSize(5)


    -- This sets the line thickness
    strokeWidth(5)
if showKeyboard() == nil then

    showKeyboard()
    -- Do your drawing here
    end
end    
if writestage == 16 then
    progress = 1
    progress2 = 1
level = 2
hacked = "Facebook hacked!"
end
end

function keyboard(k)


    if k == " " then
        hacked = ""
        if write ~= level1[writestage] then
            print(write)
            print("Success")
            write = nil
        hideKeyboard()
        write = nil
        showKeyboard()
        width = textSize(level1[writestage])
        if writestage <= 10 and level == 1 then 
        progress = progress + width + 6.20
        end
        writestage = writestage + 1
        print(write)
        if writestage >= 12 and level == 1
            then
            progress2 = progress2 + width + 6.2
            end

            if writestage <= 26 and level == 2 then
            progress = progress + width + 7
            end

            if writestage >= 27 and level == 2 then

                progress2 = progress2 + width + 7

                end 

        end



        write = nil
        hideKeyboard()

    end


    end

Thanks in advance.

Comments

  • Posts: 1,595

    Take the max that progess1 and progress2 can be then divide each by textSize().x value of the text by the max amount of progress(1 then 2) and multiply by each accordingly, hope that helps.

  • Posts: 577

    @Luatee I don't think thats the problem, progess 1 is for the first row, and progress two is for the second. I'm trying to figure out why

    width = textSize(level1[writestage])
    

    Isn't doing anything.

  • Posts: 1,595

    Here is it working for the first level, I split the text in to 2 to get the different widths.

    --The name of the project must match your Codea project name if dependencies are used. 
    --Project: Hacker
    --Version: Alpha 2.5
    --Comments:
    
    -- Hacker
    
    -- Use this function to perform your initial setup
    displayMode(FULLSCREEN)
    function setup()
        hacked = ""
        progress = 1
        progress2 = 1
        level = 1
        writestage = 1
        write = nil
        level1 = {"struct", "group.info", "init.groups", "!", ".usage", "!", "atomatic.init(2)", "end", "if", "ddos.sur", "then", "init.groups", "!", "nil", "end", 
    
         "struct", "sprint.IP", "caller.back", "return", "!", "blockage(7)", "end", "if", "sprint.IP", "and", "caller.back", ".!", ".blockage(return)", "then", "sprint.IP", "!", "LAN"}
    
    end
    
    -- This function gets called once every frame
    function draw()
    
        if writestage ~= #level1 + 1 then
         write = keyboardBuffer()
        -- This sets a dark background color 
        background(27, 27, 27, 255)
        fill(44, 100, 31, 255)
        fontSize(25)
        local str1 = "struct group.info init.groups ! .usage ! atomatic.init(2) end if ddos.sur"
        local str2 = "then init.groups ! nil end"
        if level == 1 then
        text(str1, 380, HEIGHT - 25)
        text(str2, 140, HEIGHT - 60)
        elseif level == 2 then text("struct sprint.IP caller.back return ! .blockage(7) end if sprint.IP and\n caller.back .! .blockage(return) then sprint.IP ! LAN", 368, HEIGHT -40)
        end
        write = keyboardBuffer() noStroke()
        local w,h = textSize(str1)
        fill(40, 53, 27, 112)
        rect(0, HEIGHT - 40, (w/208)*progress, 30)
        local w2,h2 = textSize(str2)
        rect(5, HEIGHT - 75, (w2/83)*progress2, 30)
       if write ~= nil then 
        fill(52, 86, 31, 255)
       text(write, WIDTH/2, HEIGHT/2)
    end
    
    text(hacked, WIDTH/2, HEIGHT/2 + 100)
    fontSize(5)
    
    
        -- This sets the line thickness
        strokeWidth(5)
    if showKeyboard() == nil then
    
        showKeyboard()
        -- Do your drawing here
        end
    end    
    if writestage == 16 then
        progress = 1
        progress2 = 1
    level = 2
    hacked = "Facebook hacked!"
    end
    end
    
    function keyboard(k)
    
    
        if k == " " then
            hacked = ""
            if write ~= level1[writestage] then
                --print(write)
                --print("Success")
                write = nil
            hideKeyboard()
            write = nil
            showKeyboard()
            width = textSize(level1[writestage])
            if writestage <= 10 and level == 1 then 
            progress = progress + width + 6.20
            end
            writestage = writestage + 1
            --print(write)
            if writestage >= 12 and level == 1
                then
                progress2 = progress2 + width + 6.2
                end
    
                if writestage <= 26 and level == 2 then
                progress = progress + width + 7
                end
    
                if writestage >= 27 and level == 2 then
    
                    progress2 = progress2 + width + 7
    
                    end 
    
            end
    
            write = nil
            hideKeyboard()
    
        end
    
    
        end
    
    
  • Posts: 577

    @Luatee Thanks, it works! What was the problem though, doc'?

  • Posts: 1,595

    As I explained above, you need to get the text size and divide it by the max the progress of that text can be then multiply it by the actual value of progress which gives you the correct size. textSize works like this local w,h = textSize(string) as there are two values width and height

Sign In or Register to comment.