Use for loop to add items to Array?

I think I may be missing something obvious, but I have been beating my head against the wall with this. 

Why does this work?

var vibeData = [new Attention.VibeProfile(50, 2000)];

vibeData.add(new Attention.VibeProfile(0, 2000));
vibeData.add(new Attention.VibeProfile(50, 2000));

vibeData.add(new Attention.VibeProfile(0, 2000));
vibeData.add(new Attention.VibeProfile(50, 2000));

vibeData.add(new Attention.VibeProfile(0, 2000));
vibeData.add(new Attention.VibeProfile(50, 2000));

But this does not?

var vibeData = [new Attention.VibeProfile(50, 2000)];
for( var i = 0; i < 3; i++ ) {
    vibeData.add(new Attention.VibeProfile(0, 2000));
    vibeData.add(new Attention.VibeProfile(50, 2000));
}

I feel like they should both do the same thing, but when I run it, the second thing crashes, but the first does as expected. Really appreciate the help!

  • Which SDK, which target, and what's the error say?

    Works fine for me in a widget using 3.1.7 and a f6 target.

    If the for loop is for more than 3, I do get 

    Error: Too Many Arguments Error
    Details: Failed invoking <symbol>

    When I do the Attention.virbate() call

    From the API guide:

    The vibrate method takes an Array containing at least one VibeProfile object, up to a maximum of 8,

  • Thanks! I had a few 'vibeData.add(new Attention.VibeProfile(0, 2000));'s before my loop and so it was putting me over the 8 max, I didn't realise that existed.. My hope in doing this was to use a for loop with a random to make a bunch of Attention.VibeProfile(0, 2000)) because I want my watch to randomly vibrate throughout the day, no message or anything, just occasional random vibrations. The 8 max makes this not a viable way to do this though. I had first tried to accomplish my goal by using a background app, but found that vibrations are not possible from the background, so now I am back to not having any idea how I might be able to do this. Any chance you have any ideas on how to make it happen? Thanks again, I really appreciate you taking the time!

  • "because I want my watch to randomly vibrate throughout the day"

    Why?

    =============

    The array is a way of changing the pattern of vibration when the device vibrates. In other words, the array defines the characteristics of a vibration event (it has nothing to do with when the device vibrates).

    https://developer.garmin.com/downloads/connect-iq/monkey-c/doc/Toybox/Attention/VibeProfile.html