Some java broke my file
Jun 03, 2019
Firstly, I know java isn't officially supported and I may be screwed but here's the deal. I've got this object that had some working bits of java in it. Mainly to print a results page but they want it to be able to be emailed. So I got some java code from a guy in my office that works in the test form he gave me. So I modified that to fill the body with what I want and put that in and it doesn't work. But also neither does the print bit now and taking out the email code still leaves the print bit broken.
Is there anything I can do short of rebuilding the object to fix this?
Also does anyone know of any hard limits of the java system, such as character/line counts/amount of variables it can pull in etc (what i'm trying to run is 179 lines/4538 chars, mostly being get vars and some html table code for the body. I don't really know if thats alot or not but the one that does work is 32lines/1056char
32 Replies
If any code is broken in the storyline file it will stop any javascript running. Removing your other code should fix the print option
Oh phew. I thought I had deleted the new code and it still wasn't working but I'd only deleted the button to the layer that ran the code. Got rid of that and now back to where I was so thanks for that. Right now to look at this code and try to figure out what's going wrong.
You can debug using the developer console, or post here and someone can have a look at it
Is that the one from F12? I have real problems trying to get to come up for storyline tabs.
Anyway. this is the code i've got on the button. Doesn't seem to want to be pasted in so heres it in a .txt file if anyone wants to have a look see what they can see.
Cheers
First thing I see is I think line 158 is missing a ; at the end.
var postParam = "guid=" + guid + "&to=" + to + "&subject=" + subject + "&body=" + body
Sorry, it's early, looks like a bunch of lines at the top are missing them too... :) Lines 4 - 56.
Agree with Michael loads of missing semicolons
Probably more errors, try running it through an online JS checker
You are also requesting a built in results variable which will unlikely send to javascript, you need to assign a user created variable to that value and send.
The code I had before works and that is basically exactly the same. The only things i have actually changed are filling in the body with the table and adding the get vars
This is what I was given originally and this definitely does work
Which one is that? the results.scorepoints ones?
That's weird, I'm pretty sure line 6 there needs a semi-colon at the end.
There are missing semicolons at the end of most lines, I can see a missing bracket and I don't think calling the results variable will work.
I have not had a look at the table formatting, but suspect there are errors in that. Try writing the code in something like Atom that will highlight any syntax errors. I would generally write in steps so I know which bit doesn't work, it is laborious to test but at least you can see where you are going wrong.
I would say line 6 and 30 need semicolons
I have it in notepad++ and nothing that I can see looks out of place and like I say. The original code does work and that has none of the ; that are missing so i'm less inclined to think that is what stopping it and as far as I can tell my table works fine (http://learn.nwrc.ac.uk/_teldemo/Test/skillstest/tabletest.html)
I don't think notepad++ is reliable for checking js syntax errors, at least from what I've seen. That's what I use too. Fix those errors and it may work.
I would add semicolons to all the lines. I would also not call the results variables but set another variable within storyline and call that.
Then work your way through the errors line 20 has missing "("
I think you have the wrong number of curly brackets in function createCORSRequest(method, url) .
I've gone through and put the ; in and now that (. Im trying to replace the bits one at a time and see where it breaks but so far i can only get the original to work. ¯\_(ツ)_/¯
What do mean not call the results variables but set another one? At the moment the values on all the question ones default to incorrect and then change to correct if the user gets it right so i'm just trying to display that value
One thing you can try is adding an alert in and moving it down through each line in the code this way you can check which bit is working
alert("Hello! Everything above me is working, something below is broken”);
For the results variables set up some numeric variables and add a trigger to assign the value of the results variable to that new variable.
Oh right do you just mean for the score part? Where would it display that alert. I havnt been able to get the f12 thing to come up when im on a storyline tab. I've made a little bit of process in that i have one with two buttons on it the one with the default which is sending and one with the same but all my getvars in which isnt. http://esprima.org/demo/validate.html this page says its syntactically valid so im going to look at that results thing next.
is there a better way to test these than publishing a new thing every time?
I would add the alert at the beginning of the file and then move down 5 lines and republish and keep going until you do not see the alert, you can guarantee an error will be in the five lines above
I have the same issue with F12. Just access the developer console from the menu instead.
where should i be looking? That sendmail comes up when i click the send button which is the original, nothing happens when i click the full button which is the same apart from the gets.
Sorry this is like trying to work in latin or something
Good morning,
I took a quick look at the java_email_code.txt file.
I don't see where player is defined. You are missing:
var player = GetPlayer();
Semicolons should also be used.
I have also never been able to access Results.ScorePoints directly with JavaScript. As a work around, create your own Points Variable and use a trigger to assign ScorePoints to your own variable. Then you can access your Points Variable with Javascript.
PROGRESS!!!!!
I removed references to the results and added that var player line at the top. One or both of those has made my button start working. I'm thinking because the original wasn't getting anything from storyline it didn't matter that line was missing. I'm now going to to another variable to take the place of that one and see if it still works.
Thanks very much to all you for the help. It is very much appreciated.
Kudos to Russell for noticing there was no GetPlayer! I think that one's important. :)
This discussion is closed. You can start a new discussion or contact Articulate Support.