So i made a little Tank Game, and now i’m trying to make it a LAN Game using a node server. So I have 4 Tanks which i need to send their position to the Node Server. But since I’ve created the original game on GDevelop, I can’t make sense of the initial code. I’ve encountered the code0.js which seems to list all existing assets, and I’ve encountered the runtimeobject.js which seems to add a this.name, this.id, this.x, etc… but i can’t figure out how to get the specific object to suit my needs. I would either like to find the Tanks objects so i can configure their position myself, or even create a new object through code if possible.
If you are making an online game I recommend you to make the game logic in the server to avoid cheating.
Basically, everything is just object definitions that you don’t need to care about. The actual important code is in the code.Js files. Each file contains definitions for the function of each scene. So function of 1 code.js = event sheet from 1 scene. Now in those event sheets, you can get an object through runtimeScene (not gdjs.RuntimeScene but runtimeScene the argument of the function of the event sheet). To do so, do something like let object = runtimeScene.getObjects("Tank")[0]
. The argument is the name of the object, and it returns an array of all the objects (that is why I added [0] at the end). If you want, you can send the object.getUniqueId()
with object.getX()
and object.getY()
to the server.
You shouldn’t change the id as this could break the engine, but to change X and Y positions use object.setX(xPos)
and object.setY(yPos)
The other file that matters are the scene definitions in data.js. It’s basically a big Js object containing all the properties of the game and scenes.
Im trying to kind of figure out/understand everything you said (btw thanks a lot, it’s all a lot clearer now), is it normal that runtimeScene is not defined. I saw that it was always used as an argument to a function so I cant do runtimeScene.getObjects
and why is there 2 objects variable /object
for exemple:
gdjs.LANCode.GDenemy2Objects1=[];
gdjs.LANCode.GDenemy2Objects2=[];
The code seems a bit weird as it is created by the computer and therefore use logic more understandable by the computer than for humans, don’t question it.
I am not sure to get your point, but the scenes event sheet is represented as a function in a code.js file. This function has to accept one parameter, Wich is runtimeScene. runtimeScene has the getObjects method.
It’s ok im starting to figure out how it’s built by looking at it. Thanks a lot I think ill be able to manage from now on. I’ll write here again if there is any other problem
Again Thanks a lot!
I was wondering if you had an idea to help me, i figured out that gdjs.LANCode.GDenemyObjects1=[]; is the whole characteristics for my player1 but when i log it in console, i get a whole array of things. Where can i find only the arguments who handle movement
Really, don’t mess around with those objects directly. Use runtimeScene.
Hi arthuro! I’ve managed to regroup the coordinates x and y of a player, and send them to another socket using node.js server and socket.io. However now i need to update those coordinates so that other players can see when im moving. Do you have any recommendations or helpful tips to help me achieve that.
Thanks!