supplierdeeply

new statement for ubasic: select/case

  • 7 Replies
  • 4570 Views
  • Publish
    new statement for ubasic: select/case
    « on: 24 / July / 2008, 14:39:55 »
    Advertisements
    Hi,
    I only write the general facts, because of my bad englich skills!

    I have developed a select/case statement for the uBasic interpreter. Currently 2 versions are available (multi and single statement version).
    Multi statement:
    - close to if/then/endif
    - slower because every case need 10ms, but save
    - use up 4 times recursive

    Single statement:
    - only one statement, needs only one tick
    - my tests are all fine, but I could be critical because of the 10ms (If anybody knows more, please let me know)
    - use X Times recursive

    Special features:
    - you can use ranges: case 1 to 5;
    - you can combine various values: case 1,3,5;
    - you can make a default statement. It means if no case was true

    Syntax:
    select EXPRESSION
      case EXPR. [to EXPR.] | [,EXPR.2[, ...]]; STATEMENT
      .
      .
      [case_else STATEMENT]
    end_select

    Example:
    Code: [Select]
    for x=1 to 7
      select x
        case 1; gosub "neu"
        case 7; goto "EXIT"
        case 2,4; print "x=2 | x=4"
        case 2 to 5; print "x=3 | x=5"
        case_else print"x=6"
      end_select
    next x
    :EXIT
      print "fertig"
      end
    :neu
      print "sub"
      for y=1 to 2
        select y
          case 1; print "y=1"
          case_else print"y=2"
        end_select
      next y
    return

    Output (multi/singleVersion):
    sub
    y=1
    y=2
    x=2 | x=4
    x=3 | x=5
    x=2 | x=4
    x=3 | x=5
    x=6
    fertig

    What do you think about this statement?

    I attached the 2 Versions as diff files

    CHDKLover
    « Last Edit: 24 / July / 2008, 15:19:32 by CHDKLover »

    *

    Offline PhyrePhoX

    • *****
    • 2253
    • make RAW not WAR
      • PhyreWorX
  • Publish
    Re: new statement for ubasic: select/case
    « Reply #1 on: 24 / July / 2008, 15:04:16 »
    great! i think this will come in very handy for scripting. unfortunately i am not much of a scripter, but let the scripting gurus speak :)
    didn't hear from you in a long time, at least here in THIS forum ;)
    by the way do you have scripts that serve a "real" purpose that already utilize this new statement? and how did you come up with the idea, or what made you think this would be good? adding this statement to the tokenizer sure as hell is alotta work and took some brains, congratz.

    edit: i think i found an example where this will be good: a game of blackjack or some other games, paired with the random function :D (just an example :D)

  • Publish
    Re: new statement for ubasic: select/case
    « Reply #2 on: 24 / July / 2008, 15:17:21 »
    Hi PhyrePhoX,
    you can use it for USB remotecontrol.

    Example:
    Code: [Select]
    do
      do
        a = get_usb_power
      until a>0
      select a
        case 0 to 20; shoot
        case 21 to 40; press "zoom_in"
        case_else press "zoom_out"
      end_select
    until is_key "set"

    CHDKLover

  • Publish
    Re: new statement for ubasic: select/case
    « Reply #3 on: 24 / July / 2008, 16:11:55 »
    Oh, this is nice :)


    *

    Offline fudgey

    • *****
    • 1705
    • a570is
  • Publish
    Re: new statement for ubasic: select/case
    « Reply #4 on: 24 / July / 2008, 16:21:34 »
    Great!

    I'd love to use this to replace ugliness like this one and have it run in one tick:

    Code: [Select]
    :get_modedialpos
      get_prop 50 X
      M=-1
      rem - AUTO --------------------   P  --------------------  Tv  --------------------  Av  ---------
      if X=-32768 then M=0 else if X=-32764 then M=1 else if X=-32765 then M=2 else if X=-32766 then M=3
     
      rem -   M  -------------------- 3 DIFFERENT VIDEO MODES --------
      if X=-32767 then M=4 else if X=2597 or X=2598 or X=2599 then M=5
    return

    *

    Offline PhyrePhoX

    • *****
    • 2253
    • make RAW not WAR
      • PhyreWorX
  • Publish
    Re: new statement for ubasic: select/case
    « Reply #5 on: 26 / July / 2008, 14:13:35 »
    did any of you make any tests so far?
    shall i integrate it into "juciphox" and provide testbuilds, one with method a) and one with method b) ?

    *

    Offline PhyrePhoX

    • *****
    • 2253
    • make RAW not WAR
      • PhyreWorX
  • Publish
    Re: new statement for ubasic: select/case
    « Reply #6 on: 31 / July / 2008, 09:39:33 »
    alright, nobody responded, gonna use multistatement for now to be included in the collaborative branch. alright?

    *

    Offline fudgey

    • *****
    • 1705
    • a570is
  • Publish
    Re: new statement for ubasic: select/case
    « Reply #7 on: 31 / July / 2008, 10:01:45 »
    alright, nobody responded, gonna use multistatement for now to be included in the collaborative branch. alright?

    I'd like the single one more, but I don't have time to test either. I can't tell if the timing can or cannot be a problem, but I would think it's feasible to test by writing a script with enough cases to fill the 8k script size limit and comparing get_tick_count before and after to see if it takes more than 10 ms to execute the statement? If it doesn't, there can't be a problem, can there?


     

    Related Topics