Error saving Scripting DS on v3
-
Break it up into more scripts for a start. Revert back to what you had so you can fet back to parsing more data
-
@mattfox Will try that, thanks.
-
@mattfox Yes, this helped, had to move around 200 data points to the new source and divide my device group into 2, transfer the devices etc, a bit of a hassle, but now it works better. Some odd behaviour I started to notice is now gone.
Lesson learned:
Will keep Scripting source data points below 500 and script lines below 1600.Thanks a lot!
-
Do note, you can use the scripted datasources to fire off of the same context point with a delay between them.
If you are trying to avoid reusing code, store common code in the global scripts as functions. Call these common functions from your scripts. Should help clean things up.
Happy to help you with your code if you are in a position to post it here in the forums. Otherwise send me a chat message.Fox
-
Hey @mattfox ,
Sorry, I am not allowed to share code here. Will try to explain what's going on though, hopefully you'll be able to understand. Not sure if this is the best approach but this is working atm.
Yes, it would be awesome to be able to reuse code, probably if I knew more javascript I would already know the way to do so, but for now what makes the lines grow is that the same script sets 440 datapoints and checks values for them too. Those 440 datapoints correspond to 20 locations (same 22 datapoints for each location).
Right now what happens is that I get a string, this is my context variable. This string first gets split into ID and data, then that ID is looked up in an object array, with an object for each location. According to where it's found it will determine which location corresponds to that ID, enters a switch, and fires a specific function for that location.
In that function, which is the same for each location and this is why there are so many lines, what happens first is that the specific values for that location are read from the variable names for that location, then stored in an object, then that object is sent to an evaluation function (this function is perfectly reused by all 20 locations) that analyzes them and returns more values, then those values are used to set the location's values using the specific variable names for that location.
I do have a scructure for variable names, so the only things I would need is the location's id and the id from the data, and from those two IDs I could construct the strings that would represent the variable names to read and set. I mean, I could already generate those strings, but what I don't know how to do is how to pass those strings to a function that reads and sets the variables (datapoints) named as the strings that I generated with those two IDs.
I hope I am being somewhat clear with my explanation.
Many thanks in advance! -
This string first gets split into ID and data, then that ID is looked up in an object array, with an object for each location. According to where it's found it will determine which location corresponds to that ID, enters a switch, and fires a specific function for that location.
So in a global script:
//takes out the fluff in the script function mapLocationToFunction(id) { var obj = {id1:loc1,id2:loc2}; //for example return obj[ id ]; } function fireLocationFunction(location,contextPt) { switch(location) [ case 'a': //do something break; } }
I do have a structure for variable names, so the only things I would need is the location's id and the id from the data, and from those two IDs I could construct the strings that would represent the variable names to read and set. I mean, I could already generate those strings, but what I don't know how to do is how to pass those strings to a function that reads and sets the variables (datapoints) named as the strings that I generated with those two IDs.
//Going out on a limb here... pt.set( generateCmdString("id", "LocId") ); //inside global function generateCmdString(id,locId) { //function logic in here return strValue; }
Just to spark your imagination. Maybe go with something on a smaller scale or similar fashion. I can likely help you with that without you having to expose your codebase...
Fox
-
@mattfox wow okay thank you!
Just a doubt with this part:
//Going out on a limb here... pt.set( generateCmdString("id", "LocId") );
This is I think my main problem, what I'm probably not getting is, how can "pt" refer to the different points that I have?
My lines are mostly:
location1_deviceId_value1.set(result1); location1_deviceId_value2.set(result2); ... locationN_deviceId_valueN.set(resultN);
So from your ideas (which are great) what I'm still not getting is how to call the different set methods for the different points based on the generated strings? This is probably not possible but if it is, it probably looks kinda like:
//Generating strings that are the variable names var variableNames=generateCmdString(id, locId); //Calling the read function var valuesToEval=readValues(variableNames); //Reading script variables //**my doubt is here function readValues(variableNames){ var values=[]; for(var k=0; i<variableNames.length; k++){ values.push(${variableNames[k]}.value); //how to do this? } return values; } //Analizing var results=eval(values); //Setting //**my doubt is also here for(var j=0; j<variableNames.length; j++){ ${variableNames[j]}.set(results[j]); //how to do this? }
I'm not sure if this would even be necessary if I followed your approach, but the
pt.set( generateCmdString("id", "LocId") );
line confused me a bit. If I'm wrong and this isn't necessary, the part that I'm probably not getting is the first one, where the locations object is defined. Would there be functions inside that object?
Greetings.
-
@jflores13 said in Error saving Scripting DS on v3:
If I'm wrong and this isn't necessary, the part that I'm probably not getting is the first one, where the locations object is defined. Would there be functions inside that object?
D'accord!
You can definitely put a function in an object. Do note you cannot wrap it into a JSON string though!
Either:var methodObj = { key1:function(arg){ return arg+1 } }
Or
var key1Fn = function(arg){return arg + 1;}; var methodObj = {key1:key1Fn};
As for your concern with points. Take a look at this script I wrote for another user:
//Get all points attached to the script context for(var pt in CONTEXT_POINTS) { this[ pt].set(value); }
This will allow you to loop through all items in the context.
In your case it would be
var values = []; for(var pt in CONTEXT_POINTS) { values.push(this[pt].value); }
Alternatively... rather than linking every point to that context group, use an RQL query instead,,,
EDIT:
Just had another read through your example, it takes a few tries to get my head around what you need... and saw eval, don't use it!//Analizing var results=eval(values); //DO NOT USE EVAL, EVAL == EVIL
Fox
-
Hey, @mattfox !
Okaaaay I think I get it now, looks like I should really take some time to program and test following your suggestions. From what I'm seeing, the use of "this" might be the key.
For the RQL query, how can I identify the points if the XID and variable name aren't an option? Can data point tags help with this?
By the way, it was very dumb from me to use "eval" as a function name example, but that's not my actual function name and I'm not using the javascript eval, was just too lazy to write something like "evaluationFunction" hahaha. I think my function is called something like "calculateResults" in spanish.
Many thanks once again!
Greetings. -
@jflores13 said in Error saving Scripting DS on v3:
Hey, @mattfox !
Okaaaay I think I get it now, looks like I should really take some time to program and test following your suggestions. From what I'm seeing, the use of "this" might be the key.
For the RQL query, how can I identify the points if the XID and variable name aren't an option? Can data point tags help with this?You can indeed! Tags will definitely help in this instance.
Like I said, we do not need to have your exact code. But! If we can mimic it, you will be in a better position to realise a solution.Or we scrap what you have and define a new solution for you based upon what we have discussed in these posts.
Fox
-
Hi @mattfox ,
You can indeed! Tags will definitely help in this instance.
Like I said, we do not need to have your exact code. But! If we can mimic it, you will be in a better position to realise a solution.Alright, excellent! Let me first find the time to try and do it on my own, and if something fails I'll let you know how far I got here.
With your help the emergency is gone for now, so we can take some time to improve it.
Thank you, have a great day!
-
Anytime, happy to help!
Fox