
Hello all! I know I'm not the most experienced when it comes to API and JavaScript, in general, but I am not sure how to interrpuret these results: --------------------------------------------------------------------------------------------------------------------------------- Script on('chat:message', function(msg) { log("-----BEGIN-----"); if (state.runCount === undefined){state.runCount = 0}; log("run count = " + state.runCount); state.gmnoteTest = [""]; if (msg.type == 'api' && msg.content.indexOf('!CharLoad') !== -1) { var testSheet = findObjs({ name: "Test Character", _type: "character" }); log("calling arrayAssign where testSheet ="); log(testSheet); state.gmnoteTest = arrayAssign(testSheet); log("state.gmnoteTest is now = "); log(state.gmnoteTest); } log("run count = " + state.runCount); log("------END------"); }); function arrayAssign(sheet) { log("Entering array assign"); sheet[0].get("gmnotes", function(gmnotes) { var newArray = gmnotes.split("<br>"); log("inside array assign and newArray = "); for (var i = 0; i < newArray.length; i++) { log(newArray[i]); } state.runCount++; log("exit array assign"); return newArray; }); //need to work with the split array inside of the function it seems //or use states } --------------------------------------------------------------------------------------------------------------------------------- Output "-----BEGIN-----" "run count = 15" "calling arrayAssign where testSheet =" [{"name":"Test Character","bio":"","gmnotes":1400026514992,"archived":false,"inplayerjournals":"","controlledby":"","_id":"-JLnQi_Lj_W_GNCTcVbK","_type":"character","avatar":""}] "Entering array assign" "state.gmnoteTest is now = " undefined "run count = 15" "------END------" "inside array assign and newArray = " "line 1" "line 2" "line 3" "exit array assign" "-----BEGIN-----" "run count = 16" "calling arrayAssign where testSheet =" [{"name":"Test Character","bio":"","gmnotes":1400026514992,"archived":false,"inplayerjournals":"","controlledby":"","_id":"-JLnQi_Lj_W_GNCTcVbK","_type":"character","avatar":""}] "Entering array assign" "inside array assign and newArray = " "line 1" "line 2" "line 3" "exit array assign" "state.gmnoteTest is now = " undefined "run count = 17" "------END------" "-----BEGIN-----" "run count = 17" "calling arrayAssign where testSheet =" [{"name":"Test Character","bio":"","gmnotes":1400026514992,"archived":false,"inplayerjournals":"","controlledby":"","_id":"-JLnQi_Lj_W_GNCTcVbK","_type":"character","avatar":""}] "Entering array assign" "inside array assign and newArray = " "line 1" "line 2" "line 3" "exit array assign" "state.gmnoteTest is now = " undefined "run count = 18" "------END------" --------------------------------------------------------------------------------------------------------------------------------- The intent here is to make sure I know how I am going to work with the gmnotes on the character sheet for my project to load data from the gmnotes to the Character Sheet. This should be possible with the new function available on dev to read the gmnotes from the sheet. The first problem I have, and you will notice that some logs with arrays are on two lines, is that if you include an array in a log, you don't get the proper output. A minor issue resolved by putting the log of the array on a separate line. The second problem, you will see in run 15 that sometimes my order of operations seems to be out of whack. In the example output, I simply did three consecutive runs. Only the last two appear to process the desired order correctly. Generally, this only happens a couple times after a new save, but it's not 100% predictable. Third, I cannot seem to update the state.gmnoteTest array with the called function's newArray value, even though the newArray is working as I intend, show my the looped output inside the function. I would greatly appreciate any insight or direction the community or Roll20 staff might have. Thanks!