Forum Discussion

DavidNowlin-f8a's avatar
DavidNowlin-f8a
Community Member
18 days ago
Solved

Using AI JAVA Script

I have almost no JAVA programming knowledge. I asked ChatGPT to make a JAVA code for a two dial system where one dial advances the cursor and the other rotates through A-Z, 0-9. (One dial with six steps and another with 36). Is the ChatGPT code anywhere close to what I need? Any help would be greatly appreciated. Thanks

  • What exactly are you trying to accomplish here?

    The AI has generated some code for you, but it might not be a complete solution due to insufficient information provided to the AI. While we all want to leverage AI as much as possible, it's not always as simple as we expect. It's important to have a basic understanding of programming and the ability to write at least simple code that can be improved upon with AI. Often, we need to correct the AI, letting it know when the code isn't working as intended. This might involve providing more information about the project structure, the variables in use, and the objects responsible for specific actions. We also need to learn how to use developer tools and the console to search for errors that might break our code, and be able to either correct them ourselves or ask the AI to identify potential issues.

    Unfortunately, the code provided to you by the AI is not useful, even though it appears clean and free of syntax errors. It breaks as soon as the slide loads, but this is only because of two extra lines at the top that are unrelated to the code and should be removed (JavaScript, CopyEdit). To start with, you need to let the AI of dial objects and variables associated to these dials. Otherwise, the AI will continue generating non-functional codes, and it can't certainly be blamed for that.

    Try executing the script below when Dial920 changes, and reference the charIndex variable on the slide to see what happens. Based on this code, you can gradually improve your AI-generated code and integrate the second dial and more variables into a single script. Don't forget to disable all other JS triggers as you are loading the same code over and over.

    var dialValue = player.GetVar("Dial920");
    var characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
    
    if (dialValue >= 0 && dialValue < characters.length) {
        var charIndex = characters.charAt(dialValue);
        setVar("charIndex", charIndex);
    }

     

  • JoeFrancis's avatar
    JoeFrancis
    Community Member

    Keep in mind that Java and JavaScript are two COMPLETELY different languages. Before it was called "JavaScript," it was called LiveScript by the folks at Netscape (of Navigator fame) before being re-branded "JavaScript" (to jump on the dot-com boom train). Storyline provides for JavaScript within its development environment, not Java.

  • The program was written in JavaScript, I mistyped. Any thoughts on where I can get assistance with this programing?

    • Nedim's avatar
      Nedim
      Community Member

      Is this what you are after?

  • Nedim's avatar
    Nedim
    Community Member

    What exactly are you trying to accomplish here?

    The AI has generated some code for you, but it might not be a complete solution due to insufficient information provided to the AI. While we all want to leverage AI as much as possible, it's not always as simple as we expect. It's important to have a basic understanding of programming and the ability to write at least simple code that can be improved upon with AI. Often, we need to correct the AI, letting it know when the code isn't working as intended. This might involve providing more information about the project structure, the variables in use, and the objects responsible for specific actions. We also need to learn how to use developer tools and the console to search for errors that might break our code, and be able to either correct them ourselves or ask the AI to identify potential issues.

    Unfortunately, the code provided to you by the AI is not useful, even though it appears clean and free of syntax errors. It breaks as soon as the slide loads, but this is only because of two extra lines at the top that are unrelated to the code and should be removed (JavaScript, CopyEdit). To start with, you need to let the AI of dial objects and variables associated to these dials. Otherwise, the AI will continue generating non-functional codes, and it can't certainly be blamed for that.

    Try executing the script below when Dial920 changes, and reference the charIndex variable on the slide to see what happens. Based on this code, you can gradually improve your AI-generated code and integrate the second dial and more variables into a single script. Don't forget to disable all other JS triggers as you are loading the same code over and over.

    var dialValue = player.GetVar("Dial920");
    var characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
    
    if (dialValue >= 0 && dialValue < characters.length) {
        var charIndex = characters.charAt(dialValue);
        setVar("charIndex", charIndex);
    }

     

    • DavidNowlin-f8a's avatar
      DavidNowlin-f8a
      Community Member

      Thank you. This does get me the first character. I think I will be able to add the additional characters.

      • Nedim's avatar
        Nedim
        Community Member

        See the attached file and explore how everything works. I've used only two triggers with two short JavaScript snippets.

        Before you start any project that could become complex, always try to leverage Storyline as much as possible. See what can be done with just Storyline triggers. When you hit a wall, start looking for JavaScript solutions that can enhance your project and add more functionality that can't be achieved with Storyline alone.

        By copying and pasting JavaScript code that works but you don't understand, you won't just miss out on learning JavaScript — you'll also miss the opportunity to fully understand how Storyline works.

  • I left school at the same time that JavaScript was developed, and I never had an opportunity to take a programming class. You mentioned the developer tool to debug JavaScript. Where would you recommend someone start learning JavaScript and the developer tool? There are numerous JavaScript YouTube videos, each with its own take on programming and slightly different take on how to think about it. For me, this makes learning slightly confusing. Do you have any resources (books or software) to recommend? 

    • Nedim's avatar
      Nedim
      Community Member

      There are countless courses available on YouTube. Pick one and stick with it — avoid jumping between tutorials from different authors. I recommend the "Traversy Media" channel, and you can start with the JavaScript Crash Course for Beginners. It's important not to give up when things start to feel boring; often, just beyond that point, the real fun begins. Always pause the video and create a simple piece of code to replicate what you've learned so far. Don't just copy and paste — make sure you understand the concepts. This course also covers using the console, which is an essential tool for debugging and testing your code, helping you track errors and see the output in real time.

    • JoeFrancis's avatar
      JoeFrancis
      Community Member

      When they were still a thing 😀 I had a small library of JavaScript books, which are now WOEFULLY out of date, along with all of my ASP/VBScript books.

      My go-to when I need a quick refresher on the syntax of a function in JavaScript is W3Schools JavaScript site. They also provide a "sandbox" environment to test out code snippets before you deploy them. Here are a few others:

      Zsolt Olah's POP(99); contains plenty of JavaScript ideas and examples for beginners and advanced developers.

      David Anderson penned Using JavaScript and Articulate Storyline, which includes examples from several contributors in the community.

      Mark Spermon has a series of videos dedicated to Storyline development, including How to Enhance your Articulate Storyline 360 courses with JavaScript. Check out his YouTube channel.

      HTH

      • Ange's avatar
        Ange
        Community Member

        I second w3Schools, it is a fantastic well organized resource. It also offers CSS, HTML and more. CSS and HTML are well worth becoming familiar with, for example for customizing Storyline print output, Rise design..., etc.

  • Dave-Ruckley's avatar
    Dave-Ruckley
    Community Member

    I've used ChatGPT a lot to generate javascript for me and it's been a great resource. The main thing to remember is that it probably won't work straight away and you'll have to refine your prompts to it using any errors you get in the browser console and describing anything that does happen (even if it's not what you expect). I've found that if you can give it the details of where it seems to be failing it has a much better chance of fixing the code.