RedPower Basic item request system

Discussion in 'Programming' started by sk89q, Jan 8, 2013.

  1. sk89q

    sk89q Administrator
    Staff Member

    Joined:
    Dec 1, 2011
    Messages:
    2,490
    Likes Received:
    1,504
    This is something I wrote a while back to power the item request system on our Alice base. It'd ask you the item index, followed by the number of stacks, and the program would emit the respective signal on bundled cable a certain number of items according to the number of stacks. The wires themselves were connected to retrievers.

    Code:
    VARIABLE INPUT 5 ALLOT
     
    : ** ( n1 n2 -- n1**n2 )
    1 SWAP ?DUP IF 0 DO OVER * LOOP THEN NIP
    ;
     
    : DOREQ ( index count -- )
    ." PLEASE WAIT..."
    0 DO DUP IOX! 10 TICKS 0 IOX! 10 TICKS LOOP DROP
    CR ." Done" CR
    ;
     
    : ACCEPTNUM
    INPUT 6 ACCEPT ATOI CR
    ;
     
    : REQCNT ( index -- )
    ." # stacks?" CR
    ACCEPTNUM DUP DUP 1 >= SWAP 30 <= AND
    IF DOREQ ELSE ." INVALID" 2DROP THEN
    ;
     
    : REQIDX
    ." Item #?" CR
    ACCEPTNUM DUP DUP 0 >= SWAP 15 <= AND
    IF 2 SWAP ** REQCNT ELSE ." INVALID" DROP THEN
    ;
     
    : MAIN
    PAGE BEGIN
    ." -- REQUEST ITEMS --" CR
    ." 0 Bonemeal    1 Oak Logs  2 Arrows" CR
    ." 3 Rubber Wood  4 String    5 Spider Eye" CR
    ." 6 Bread        7 Charcoal" CR CR
    REQIDX CR CR CR CR
    AGAIN
    ;