Shop OBEX P1 Docs P2 Docs Learn Events
Counter FOR...NEXT loops — Parallax Forums

Counter FOR...NEXT loops

ktdid07ktdid07 Posts: 8
edited 2008-05-04 14:41 in Learn with BlocklyProp
Hey, guys (it's me again).

I was looking for a little (more) programming help. What I'm trying to do is make a counter count up by "round" and as each round gets higher, it sends it to another subroutine. In other words, the first Round is Round 1, and when it hits round one, it goes to RANDOM_SEQUENCE1 subroutine and does what is there. When it finishes that and the user gets the answer right, I want it to count up another 1 and go to Round 2, and thus RANDOM_SEQUENCE2. Get what I'm saying?

The code in my non-computer programmer head looks something like this, which is a combination of BASIC stamp language and what I wish BASIC stamp language could say.

SETUP:
FOR Round = 1 TO 6
· GOTO RANDOM_SEQUENCEX


With X indicating the round as it counts up. Is there a way to make BASIC stamp recognize variables like that? I am sure that I've seen the use of variables somewhere in BASIC stamp, but could anybody help me out with the routine?

Thanks so much.
·

Comments

  • PJAllenPJAllen Banned Posts: 5,065
    edited 2008-05-02 03:38
    OHNOITSHIMAGEN

    Take a look at ON...GOTO in PBASIC Help

    FOR round = 0 TO 5
    ON round GOTO Rnd0, Rnd1, Rnd2, Rnd3, Rnd4, Rnd5
     
    ...
    
  • ktdid07ktdid07 Posts: 8
    edited 2008-05-02 04:38
    That command is very helpful. But now, for some inexplicable and absolutely abysmal reason, my "random number generator" will only generate one number. Any ideas? I've posted code below.

    NumberPicker:
    numgen = 11500
    RANDOM numgen
    DEBUG DEC ? numgen
    myNum = numgen/6550 MIN 1
    DEBUG DEC ? myNum
    'IF myNum > 0 < 4 THEN AssignPress
    'IF myNum > 4 OR 0 THEN
    RETURN
  • Brad_HBrad_H Posts: 35
    edited 2008-05-02 06:28
    ktdid07

    RANDOM needs a different seed value each time

    Brad
  • jmalaysiajmalaysia Posts: 97
    edited 2008-05-04 14:41
    The seed value declaration needs to be moved out of the NumberPicker subroutine.· Only assign the seed value once,· then each time thru the NumberPicker subroutine the seed value numgen will be the result of the previous pass thru the subroutine.
Sign In or Register to comment.