Howdy, Stranger!

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

In this Discussion

beu5mi's variable generator

edited June 2012 in Code Sharing Posts: 16
-- Use this function to perform your initial setup


function setup()
    clearLocalData()
    
    alphabet = {"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"}
    
    iparameter("choose_a_letter_by_its_number",1,26,5)
    iparameter("how_many", 1, 20, 7)
    iparameter("value_of_how_many", 1, 200)
    
    surrogate_string = alphabet[choose_a_letter_by_its_number]..how_many
    print("new variable! "..surrogate_string)
    saveLocalData(surrogate_string, value_of_how_many)
    surrogate_string2 = readLocalData(surrogate_string)
    print("with its own new value! "..surrogate_string2)
    print("together now "..surrogate_string.." = "..surrogate_string2)
    
end




-- This function gets called once every frame
function draw()
    -- This sets a dark background color 
    background(40, 40, 50)

    -- This sets the line thickness
    strokeWidth(5)
end
function touched(touch)
     
        clearParameters()
    iparameter("choose_a_letter_by_its_number",1,26,choose_a_letter_by_its_number)    
    iparameter("how_many", 1, 20, how_many)
    iparameter("value_of_how_many", 1, 200)

    surrogate_string = alphabet[choose_a_letter_by_its_number]..how_many
    print("new variable! "..surrogate_string)
    saveLocalData(surrogate_string, value_of_how_many)
    surrogate_string2 = readLocalData(surrogate_string)
    
    print("with its own new value! "..surrogate_string2)
    print("together now "..surrogate_string.." = "..surrogate_string2)
    
end
Description = "Completely parameterized variables"
Author = "beu5mi"
saveProjectInfo("Description", Description)
saveProjectInfo("Author",Author)
print(Description.." by "..Author)

Comments

  • edited June 2012 Posts: 16

    Here's a slightly nicer version of it that can alter a variable in use



    -- Use this function to perform your initial setup function setup()     clearLocalData()          alphabet = {"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"}          iparameter("choose_a_letter_by_its_number",1,26,5)     iparameter("how_many", 1, 20, 7)     iparameter("value_of_how_many", 1, 200)     clearOutput()     surrogate_string = alphabet[choose_a_letter_by_its_number]..how_many     print("new variable! "..surrogate_string)     saveLocalData(surrogate_string, value_of_how_many)     surrogate_string2 = readLocalData(surrogate_string)     print("with its own new value! "..surrogate_string2)     print("together now "..surrogate_string.." = "..surrogate_string2)      end -- This function gets called once every frame function draw()     -- This sets a dark background color      background(40, 40, 50)     -- This sets the line thickness          if surrogate_string == "x1" then     clearOutput()     x1 = surrogate_string2     print("hijacked!")          elseif surrogate_string == "y1" then        y1 = surrogate_string2     clearOutput()     print("hijacked!")      end          if x1 == nil then      x1 = 100     elseif x1 > 100  or x1 < 100 then          print("youve changed x!"..x1)     end     if y1 == nil then      y1 = 50     elseif y1 ~= 50 then              print("youve changed y!")     end local fs = alphabet[choose_a_letter_by_its_number]..how_many.." = "..value_of_how_many fill(255) font("ArialMT") text("Tap here to lock in these values",WIDTH/2,HEIGHT/2 + 130)     text(fs,WIDTH/2,HEIGHT/2)     fill(227, 14, 14, 255)     ellipse(x1,y1,25) end function touched(touch)               clearParameters()     iparameter("choose_a_letter_by_its_number",1,26,choose_a_letter_by_its_number)         iparameter("how_many", 1, 20, how_many)     iparameter("value_of_how_many", 1, 200) clearOutput()     surrogate_string = alphabet[choose_a_letter_by_its_number]..how_many     print("new variable! "..surrogate_string)     saveLocalData(surrogate_string, value_of_how_many)     surrogate_string2 = readLocalData(surrogate_string)          print("with its own new value! "..surrogate_string2)     print("together now "..surrogate_string.." = "..surrogate_string2)      end Description = "Completely parameterized variables" Author = "beu5mi" saveProjectInfo("Description", Description) saveProjectInfo("Author",Author) print(Description.." by "..Author)

    but it had to be specially coded for it to work that way is there any other way I could have coded this?

Sign In or Register to comment.