0

Sorry about the title, not very good with those so here is a little explanation;

I want to fully go through the array 'ids', and once I am complete with the last one I want to set i to 1 again, would this if statement work?

if(i === ids.length){
    i = 1
    print(i)
}

Full Code:

var ids = ["232494086", "110891941", "232746775", "50382985", "108147528", "110207437", "232532449", "232532377", "151784429", "63043890", "1029025", "116777149", "1365767", "98346834", "100929604", "82332012", "215751161", "232491040", "20052135", "209995252", "19264845", "81725506", "35292167"]

function Post(Id,Comment){
        $.get("http://www.roblox.com/Item-item?id=" + Id).always(function(Data){
                var Token = Data.match(/setToken(\W(.+)\W);/)[2].replace(/'/g,"")
                Token = Token.replace("+","%2B").replace("/","%2F")
                $.post("http://www.roblox.com/API/Comments.ashx?rqtype=makeComment&assetID=" + Id + "&token=" + Token,Comment)
                document.write('<a target="_blank" href="http://www.roblox.com/Item-item?id='+Id+'">'+Id+'</a><br/>')
        })
}

function getCatalog() {
  var ids = [];
  var json = $.getJSON( "http://www.roblox.com/catalog/json", function( data ) {
    //alert(data[1]['AssetId'])
    var len = Object.keys(data).length;
    for (i = 0; i < len; i++) {
      ids.push(data[i]['AssetId']);
    }
    console.log('var ids = ["'+ids.join("\", \"")+'"]');
  });
}

var msg = 'Send me trades!'

Post(ids[0],msg);

var i = 1;

var Interval = setInterval(function(){
        Post(ids[i],msg)
        i++
    if(i === ids.length){
        i = 1
        print(i)
    }
},300000)
devin
  • 113
  • 1
  • 1
  • 6

1 Answers1

0

If I understand you right... I would say you have to set it to 0 if you want to go again through it, and do -1 on length:

if(i === ids.length-1){
    i = 0;
    print(i)
}

what im not sure about is your document.write there, what is your goal?

...The write() method is mostly used for testing: If it is used after an HTML document is fully loaded, it will delete all existing HTML...

reyaner
  • 2,799
  • 1
  • 12
  • 17