Re: GuideMe Scripting Engine
Posted: Thu Sep 20, 2018 12:36 am
Deleted and combined in prior post
Code: Select all
// We reach here if str was an alphanumeric string like a variable name, or just a string.
// Check to see if it's the name of a defined variable
var temp = scriptVars.get(str);
// jscriptLog(myName+"temp=" + temp);
if ( temp != undefined ) {
// It was a defined scriptvar so return it's value
if (temp === true || temp === false) return temp; //BOBHILL ADD
else if ( ! isNaN(temp) ) { //It's either a number or a string
// It's a number so just return it in the proper form
if ( parseInt(temp) == parseFloat(temp) ) return parseInt(temp); // Must be an int
else return parseFloat(temp); // It's a float. Not a root beer float, a number float.
}
else return temp; // Must be a string so just return it
}
Code: Select all
else {
// We have the start of some other expression element
// Find the next delimiter character (opening or closing parentheses, operator or space) **** OR COMMA **** BOBHILL
// If we are parsing a special function argument we ignore plus signs
if ( isFunctionArg ) while (end < expression.length && expression.charAt(end).search(/[\s\(\)\<\>\,\=\!\-\*\/\"]/) == -1 ) end++; //added comma BOBHILL
else while (end < expression.length && expression.charAt(end).search(/[\s\(\)\<\>\,\=\!\+\-\*\/\"]/) == -1 ) end++; //added comma BOBHILL
// jscriptLog(myName+"end=" + end + ", char=\"" + expression.charAt(end) + "\"");
Hi bobhill,bobhill wrote: ↑Wed Sep 19, 2018 12:20 pm I am calling a script from a GM page.
On the final page of the script, I have buttons to exit, such as "North", "South" and I have GM pages that these buttons should go to. Here's the updated code:
<snip>
I've tried various methods - and they do go to the correct GM page, but for some reason, the text portion of ShowScriptPage is displayed ("Something went wrong") before proceeding to the target GM page called from the script. I don't see anything in the js or gm logs that indicate why this is happening. I've stepped through the js code and and ShowScriptPage appears to be working. It recognizes the "Exit" command in the script and goes to the correct target GM page - it's just that ShowScriptPage displays the <text> component before 'target' is loaded.
EDITED: Updated script code, identified code in ScriptEngine.xml, and combined with next post
Update: this happens with Script Engine 1.50 and GM 0.3.7 combination but not with Engine 1.50 and GM 1.5.32b, so I guess it's a compatibility issue in one of the GM updates?
Interesting. I've never had need to use boolean variables in a script before so never encountered that. I've added your fix to the code for the next release.bobhill wrote: ↑Wed Sep 26, 2018 8:33 pm PlayfulGuy, I know you've been away, but two issues I've identified in 1.5: getVariable doesn't process boolean scriptVars correctly (returns NaN) and if you use more that one parameter in a js function called in a script, in evaluateExpression, the comma isn't parsed out correctly, which causes an error. Not sure if these are addressed in 1.53.
I fixed them this way in the js file: (you may have a better way)
Code: Select all
// We reach here if str was an alphanumeric string like a variable name, or just a string. // Check to see if it's the name of a defined variable var temp = scriptVars.get(str); // jscriptLog(myName+"temp=" + temp); if ( temp != undefined ) { // It was a defined scriptvar so return it's value if (temp === true || temp === false) return temp; //BOBHILL ADD else if ( ! isNaN(temp) ) { //It's either a number or a string // It's a number so just return it in the proper form if ( parseInt(temp) == parseFloat(temp) ) return parseInt(temp); // Must be an int else return parseFloat(temp); // It's a float. Not a root beer float, a number float. } else return temp; // Must be a string so just return it }
Code: Select all
else { // We have the start of some other expression element // Find the next delimiter character (opening or closing parentheses, operator or space) **** OR COMMA **** BOBHILL // If we are parsing a special function argument we ignore plus signs if ( isFunctionArg ) while (end < expression.length && expression.charAt(end).search(/[\s\(\)\<\>\,\=\!\-\*\/\"]/) == -1 ) end++; //added comma BOBHILL else while (end < expression.length && expression.charAt(end).search(/[\s\(\)\<\>\,\=\!\+\-\*\/\"]/) == -1 ) end++; //added comma BOBHILL // jscriptLog(myName+"end=" + end + ", char=\"" + expression.charAt(end) + "\"");
Great - that's what I did.You can safely remove the text node from the ShowScriptPage page in ScriptEngine.xml and that should fix it.
For the boolean test, I used the strict equality initially and it worked with GM 3.7, but I had to drop to loose equality "==" when testing with some of the other GM versions. That really doesn't make sense to me, but it works and I was tired of debugging it.I've added your fix to the code for the next release.
It's a big project and I never have enough time, but I've finally finished most of the 'infrastructure'. Even the small coding parts tend to take me a lot of trial and error to work out syntax, etc. Next, I've been working on story and scripts. I need to do more work, but will release a partial version when it's far enough along.The code snippets you posted are interesting. I'm very curious about what you're building and how it works.
Code: Select all
if (vElapsedTime < 31) goto Begs30
Code: Select all
if (vElapsedTime <= 30) goto Begs30
Code: Select all
Wait <vWait> minutes Image 161.jpg "Rest for <vWait> minutes"
bobhill wrote: ↑Mon Oct 22, 2018 4:06 am A new question, when you return: In 1.53 and GM 3.7 I am having problems with GlobalButton command, as the ScriptEngine treats it as regular text and it never runs through the "processCommands" function. I've run through the java debugger and haven't been able to identify an error yet. Thanks! BH
Hi Bob,bobhill wrote: ↑Sun Oct 28, 2018 10:19 am Hi PG - two more items I've found. I just want to mention, otherwise I will forget.
I'm having trouble using if with <= or >=. evaluateExpression seems to have problem parsing both together, but does fine if only one is used. I just adjusted to use < or > not <= or >=, I haven't found the exact point in the code where it happens yet.
Also, in the Wait.xml, if you list an image as an argument, the Wait page gets the full image path, which is also retrieved in getImage, so the path is repeated twice, resulting in image not found. I was able to work around by specifically using the "Image" parameter with the image name:
Code: Select all
Wait <vWait> minutes Image 161.jpg "Rest for <vWait> minutes"
Code: Select all
// Testing stuff for bobhill
imageFolder Models/Sarah // Sets the default image folder
GlobalButton Yes Mistress
temp = 30
if (temp <= 30) *.jpg Temp is 30 or less
set DEBUG
Wait <temp> minutes Image *.jpg "Rest for <temp> minutes"
Wait <temp> minutes Image no-06.jpg "Rest for <temp> minutes"
unset DEBUG
exit
Hi Bob,bobhill wrote: ↑Wed Sep 19, 2018 12:20 pm I am calling a script from a GM page.
On the final page of the script, I have buttons to exit, such as "North", "South" and I have GM pages that these buttons should go to. Here's the updated code:
<snip>
I've tried various methods - and they do go to the correct GM page, but for some reason, the text portion of ShowScriptPage is displayed ("Something went wrong") before proceeding to the target GM page called from the script. I don't see anything in the js or gm logs that indicate why this is happening. I've stepped through the js code and and ShowScriptPage appears to be working. It recognizes the "Exit" command in the script and goes to the correct target GM page - it's just that ShowScriptPage displays the <text> component before 'target' is loaded.
This is the part of ShowScriptPage that is being executed. Upon the 'return' command, is when the text is displayed.
Code: Select all
// Check for an Exit command (exit the script) if ( page.text == "exit" ) { // Exit the script and go somewhere else jscriptLog(myName+"Exiting script " + page.filename); target = ExitCurrentScript(); overRide.setPage(target); return; // And go do it. }
Code: Select all
overRide.setPage(target);
Code: Select all
overRide.setDelay(target,"0","","hidden","","","");
Code: Select all
overRide.setPage(page.text);
Code: Select all
overRide.setDelay(page.text,"0","","hidden","","","");
PG - Sorry, I've been away and haven't had a chance to respond. Thanks for looking at this. I'll try to run your code first to confirm I'm not doing something stupid and then I'll recheck any changes I made in the js vs a clean download.PlayfulGuy wrote: ↑Sat Nov 03, 2018 5:46 pm
I did a quick setup of a Guideme 3.7 installation with the release code for script engine 1.53 modified so the javascript files load properly, and I'm unable to reproduce these errors. Here's the script I used to test.When I run that I get the screen saying Temp is 30 or less with the global button I defined, and then I get the wait page with a random image, and then the wait page with the specified image exactly as I'd expect.Code: Select all
// Testing stuff for bobhill imageFolder Models/Sarah // Sets the default image folder GlobalButton Yes Mistress temp = 30 if (temp <= 30) *.jpg Temp is 30 or less set DEBUG Wait <temp> minutes Image *.jpg "Rest for <temp> minutes" Wait <temp> minutes Image no-06.jpg "Rest for <temp> minutes" unset DEBUG exit
I know you've made a couple other changes to the script engine code to fix some other issues and I have not replicated those code changes for this test, so perhaps one of your other changes has introduced some other issue.
Ok, thanks. If the steps above don't show anything clearly wrong to me, then I'll post the js and script. It may be a few days before I can reply.PlayfulGuy wrote: ↑Sat Nov 03, 2018 5:46 pm
If I have time and energy later I'll go back and update the code with the changes you reported earlier and see what happens. And if you could post the ScriptEngine,js file you are using and the relevant portion of the script you're building I will do some tests and try to nail it down.
Great, thanks! I'll make these changes!PlayfulGuy wrote: ↑Wed Nov 07, 2018 8:16 pm I've been digging in to this and have discovered that it seems to be an issue with the overRide.setPage() command in the newer GM versions.
Hi PG - I reran my script and I am not able to reproduce my error and your script works fine. If I have the problem again, I'll let you know.PlayfulGuy wrote: ↑Sat Nov 03, 2018 5:46 pm
I did a quick setup of a Guideme 3.7 installation with the release code for script engine 1.53 modified so the javascript files load properly, and I'm unable to reproduce these errors. Here's the script I used to test.
Excellent!
I've actually had a couple times where I would have liked the same functionality myself, and have thought about ways to implement it, but haven't settled on a good solution. Do you have a suggestion on how you would like to see it? How would you like to be able to code it?bobhill wrote: ↑Thu Dec 27, 2018 11:12 pm Separately, given the addTimer functionality in GM, would it be possible to implement a similar command in the script engine that would change the right pane html but keep the same GM page? My specific use is to have changing text/buttons on right pane with a single video playing on left pane.
I had not thought about it, but in v1.5, with the Enhanced Page Command, the default if the image field is blank is to keep the same, but it changes the page (and the right pane)(so leaving the image blank would not work for this purpose) and under the old notation, a quotation mark also keeps the same image. So, using the old syntax, would it make sense to use a different marker that could indicate to change the right pane only and not to change the GM page, such as a "#" or "%"?PlayfulGuy wrote: ↑Fri Dec 28, 2018 6:05 am Do you have a suggestion on how you would like to see it? How would you like to be able to code it?
I've spent a bit of time looking at this and have a comment on a question you ask in your sample code, and a thought on adding the timer functionality.bobhill wrote: ↑Fri Dec 28, 2018 5:42 pmI had not thought about it, but in v1.5, with the Enhanced Page Command, the default if the image field is blank is to keep the same, but it changes the page (and the right pane)(so leaving the image blank would not work for this purpose) and under the old notation, a quotation mark also keeps the same image. So, using the old syntax, would it make sense to use a different marker that could indicate to change the right pane only and not to change the GM page, such as a "#" or "%"?PlayfulGuy wrote: ↑Fri Dec 28, 2018 6:05 am Do you have a suggestion on how you would like to see it? How would you like to be able to code it?
As a potential sample, here's something adapted from the GM I'm working on:
As you said, I'm not sure you can add buttons, I'm still working on this in GM. I may need to have the buttons on the page from the start of the video and enable / disable them when applicable. Philo did mention adding a target page to the Delay commands (it needs to be both overRide and Guide, I think), which would increase flexibility around content.
- Spoiler: show
Edit - p.s. - this is very exciting, I'm glad you are interested in adding, also!!
Code: Select all
// replace 'next' with 30, which is the Delay
// could we have a label to go to when video is complete and if no label then it's assumed there's a 'wait' + button
// what can change in right pane - text and buttons or only text?
Video media/video/model.mp4 00:00:00 00:15:00, 30, EndLabel {
<vHeaderText>\n
gt Start stroking - once per second.\n\n
}
vTemp = fChangeXP(30)
Code: Select all
Video media/video/model.mp4 00:00:00 00:15:00 wait // Wait means wait for a button press
" 30 { // The timer here should make it continue even if there's no button pressed
<vHeaderText>\n
gt Start stroking - once per second.\n\n
}
vTemp = fChangeXP(30)
goto EndLabel // And then you go to EndLabel
Code: Select all
// Next means go to next page, which actually means continue processing with the next
// command, so the goto kicks in.
Video media/video/model.mp4 00:00:00 00:15:00 next
" {
<vHeaderText>\n
gt Start stroking - once per second.\n\n
}
vTemp = fChangeXP(30)
goto EndLabel // And then you go to EndLabel
Looking at the code for the script engine and the way it's structured, and looking at the addTimer() documentation and the other options it has, it occurred to me that the simplest approach is to add a Timer command to the text block processing so you could saybobhill wrote: ↑Fri Dec 28, 2018 5:42 pmI had not thought about it, but in v1.5, with the Enhanced Page Command, the default if the image field is blank is to keep the same, but it changes the page (and the right pane)(so leaving the image blank would not work for this purpose) and under the old notation, a quotation mark also keeps the same image. So, using the old syntax, would it make sense to use a different marker that could indicate to change the right pane only and not to change the GM page, such as a "#" or "%"?PlayfulGuy wrote: ↑Fri Dec 28, 2018 6:05 am Do you have a suggestion on how you would like to see it? How would you like to be able to code it?
Edit - p.s. - this is very exciting, I'm glad you are interested in adding, also!!
Code: Select all
InitialImage.jpg {
Initial text
Timer 10 New text 1
Timer 10 New text 2
Timer 10 Image newImage.jpg
}