Forum Discussion
Using AI JAVA Script
- 6 months ago
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); }
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.
Related Content
- 6 months ago
- 7 months ago
- 7 months ago