Wait for startAction to complete within a function

  • #10, by afrlmeSunday, 09. March 2014, 21:46 8 years ago
    Ok I think I know what you are getting at & damn... sliding puzzles; both mine & Nige's (methinks?) least favorite form of puzzle razz

    quick tip: if you want to keep scripts compact & use less lines then don't drop lines for every little thing... sometimes you can create a query or function on a single line.
    if bsizec == 1 and bsizer == 1 then
    ready = board[row(curpos)][col(curpos)+1] == 0
    elseif bsizec == 2 and bsizer == 1 then
    ready = board[row(curpos)][col(curpos)+2] == 0
    elseif bsizec == 1 and bsizer == 2 then
    ready = board[row(curpos)][col(curpos)+1] == 0 and
            board[row(curpos)+1][col(curpos)+1] == 0
    elseif bsizec == 2 and bsizer == 2 then
    ready = board[row(curpos)][col(curpos)+2] == 0 and
    board[row(curpos)+1][col(curpos)+2] == 0
    end
    

    to...
    if bsizec == 1 and bsizer == 1 then ready = board[row(curpos)][col(curpos)+1] == 0
    elseif bsizec == 2 and bsizer == 1 then ready = board[row(curpos)][col(curpos)+2] == 0
    elseif bsizec == 1 and bsizer == 2 then ready = board[row(curpos)][col(curpos)+1] == 0 and board[row(curpos)+1][col(curpos)+1] == 0
    elseif bsizec == 2 and bsizer == 2 then ready = board[row(curpos)][col(curpos)+2] == 0 and board[row(curpos)+1][col(curpos)+2] == 0 end
    

    or for example....
    if something then do something; print("something"); return something
    elseif other then....
    etc...
    

    I prefer to keep things compact but still keep them structured. It really helps keep amount of lines down; same goes for incrementing tables.
    t,= {}
    t[1] = ...
    t[2] = ...
    etc...
    
    -- to
    
    t = {something, "something_else"}
    
    -- or
    
    t = {"name" = "bob", "profession" = "builder"}
    

    just a few examples on keeping scripts small. also variables are good for storing links & getObjects into for quick access.

    Imperator

    7052 Posts


  • #11, by cr34m3Sunday, 09. March 2014, 22:19 8 years ago
    Thanks for the tips AFRLme, I'll implement some of them when I do a bit of code clean up.

    I'm also not a big fan of sliding puzzles, but I do believe that an original (even a little bit) and contextual (most important) implementation has its merit. Puzzle boxes are essentially sliding puzzles and they're awesome cool. smile

    Newbie

    72 Posts

  • #12, by afrlmeSunday, 09. March 2014, 22:51 8 years ago
    No problem smile

    There's probably loads of other methods or code you could replace to make it smaller/neater but I only quickly glanced over the whole script.

    puzzle boxes? you mean the Rubik's cube? http://www.rubiks.com

    Imperator

    7052 Posts

  • #13, by cr34m3Sunday, 09. March 2014, 23:04 8 years ago
    puzzle boxes? you mean the Rubik's cube? http://www.rubiks.com

    No, I mean puzzle boxes. wink
    Wikipedia / Puzzleboxworld

    Newbie

    72 Posts

  • #14, by afrlmeSunday, 09. March 2014, 23:20 8 years ago
    ah ok smile

    Imperator

    7052 Posts