repeat for item randVar of varList

Hello,

I am trying to do a repeat, but only for 1 item of a list. This item is randomly generated via the random function. The list let's just say has a-z in it separated by comma's. So the random function is (1,26). When I run the repeat it complains about it not being a number? Why is this?

This is what the error says..and I don't understand, cause it found the value in the list via the randVar, but it's complaining about it not being a number? Why?

4/12/12 1:34:45 PM logerror Runtime Error at line 220: STInvalidNumberException - Value is not a number: 'A'
4/12/12 1:34:46 PM FAILURE Script Error Number of Errors logged: 1\nExecution Time 0:00:00


Is it cause it doesn't know how many times to run? cause in the loop I'm changing the randVar to a different item number, it just has to RUN to get it.

I've also left the "for" out of the repeat and it gets the same results.

Thanks in advance,
- Joe

Comments

  • EggplantMattEggplantMatt ForumAdmin admin
    This would be easier to answer if you would post the actual code. I'm not following the logic just reading about it. I'll probably know what the problem is as soon as I see the code.
  • SenseTalkDougSenseTalkDoug ForumAdmin admin
    I think I can name that tune… ;)

    Yes, I admit I was rather baffled, too, but after puzzling over this while eating my lunch I think I can guess at most of it:

    SenseTalk allows for a certain amount of variety in how you express things. The following all mean the same thing:
    repeat for x times
    repeat x times
    repeat for x
    repeat x
    
    In your case, "repeat for item randVar of varList" matches the third format above, with x being "item randVar of varList". This needs to evaluate as the number of times that the repeat loop should be executed. I assume that in your case that expression evaluates to the letter "A", which gives the error message you're seeing.

    Without more information it's hard to say what you intended, but perhaps you were trying to repeat with each of the items in the list, in which case you need to add the word "each" in your repeat statement:
    repeat for each item randVar of varList
    
    That will set randVar to each of the items of the list in turn, on each iteration through the loop. If that isn't what you want you will need to explain more about what you're trying to do and show us more of your code.

    I notice you said that you want to repeat something, but only for 1 item, which isn't really repeating, so perhaps you don't need a repeat loop at all.
  • Yes and No.

    I don't want to repeat just one time, but I can see where that is confusing. I want it to keep repeating until it hits the the list, but randomized.

    I'm just trying to randomize a list. I don't want it to be the same order everytime. Cause if your checking against lets say "Z", I have to wait for it to check 25 times before it reaches "Z" and it's everytime. So I was trying to randomize the list so instead of (1-26), I have something like (4,23,2,15,21) etc etc...

    There is no code, I've already tried to move on, but I guess I need to know how to randomize a list and it "has" to keep going until the end of the list.

    Also it can't repeat itself as in (4,23,2,15,21,4), see there are two "4's"? That can't happen. No repeats inside the list. I've tried numerous attempts and I'm wasting too much time on it. So I hope there is an easy solution to this.

    Thanks!
  • SenseTalkDougSenseTalkDoug ForumAdmin admin
    Here is the easy way to sort any list into a random order:
    sort myList by random(10000)
    
    That will sort the items of the list using random numbers rather than based on the values in the list.
  • Shuddup, really? I was writing some stupid long repeat that randomly pulled items out of the list and put it into another list...but I could never get it to recognize if it was already in the list to NOT put it into the other list.

    This is great, thanks Doug!

    Worked like a charm, almost too easy!
Sign In or Register to comment.