chrismaltby / gb-studio

A quick and easy to use drag and drop retro game creator for your favourite handheld video game system
https://www.gbstudio.dev
MIT License
8.44k stars 467 forks source link

Calling APIs from GB Studio #1316

Open wikisimsio opened 9 months ago

wikisimsio commented 9 months ago

This was possible in GB Studio version 2.0.0 beta 4, and there is a great example provided by Chris Maltby here: https://chrismaltby.itch.io/gb-api-poc

In my opinion there is a huge potential for e-learning applications, and I have created a proof of concept example for SCORM integration based on the included demo project. If you select "Complete it" in the menu, the game communicates to the LMS that the course is completed, which you may see after closing the game window: https://app.cloud.scorm.com/sc/InvitationConfirmEmail?publicInvitationId=9f931d26-231a-4cf2-a6b1-7e2a63e4e8a9

It would be cool if a similar mod and description could be provided for the latest version of GB Studio. If not, would it at least be possible to post the release files for GB Studio version 2.0.0 beta 4 back on GitHub?

wikisimsio commented 9 months ago

UPDATE. With the help from Patrick Mollohan on Reddit I was able to figure out how to use the old guidelines for the latest version of GB Studio.

First of all, older versions used different js emulator. To use the previous emulator I basically took a project created in the old version and replaced the rom file with the one I created in the version 3.1.0. Similar mod might be possible with the new emulator, too, but the names of the functions and variables would be different.

Next, Patrick Mollohan explained to me that with the latest release of GB Studio 3 I should be looking for "_script_memory" instead of "_script_variables" in the game.map file. Finally, since GB Studio 2 used 8-bit variables and they are now 16-bits wide, the "variableIndex" value in the script should be multiplied by 2.

However, this was not the end of it. There is additional complexity because of the changes in the way variables are handled. Previously the variables had a fixed index number. In the latest version variables only have names. The sequence in which variables appear in the project is now important. Leaving some variables unused or moving the order of events may also change the index of the variable. It requires very careful naming and keeping track of the variables not to mess it up.

Anyhow, I would appreciate any feedback or comments regarding the above. For the time being I would probably prefer working with 2.0.0 beta 4 build, and I hope that somebody can provide me with the Windows 64-bit version. Or maybe I could ask someone who is more competent than me to compile it from the original source code, which I found using the wayback machine.

wikisimsio commented 9 months ago

UPDATE 2. I also figured out that it works with 2.0.0 beta 5 version, but instead of "_script_variables" you should look for "_script_v" in the game.map file. Perhaps there is no need for 2.0.0 beta 4 build then.