I just created this account because i spent two entire afternoons trying to debug the following code: (As of now it doesn’t work (but i feel like it should))
With the risk of asking a question with an obvious answer, her goes:
1 Description of problem
I recreated the link to sockets.io made by Daniel Shifman in his introduction to sockets. With this I made a send data to a server concerning the postion of every
ship in play.
This data is communicated well enough and i receive the x position from other browsers. With this I want to draw the
other )from another browser’ in the client window.
When iI console.log the data it displays fine. However when I attempt draw something with this x-value it does not display over my background. (it works if i cancel out the background).
Any suggestions as to how i can visualise my data?
Things i’ve tried:
- Setting a referencing function in draw()
- attempting to data to another variable
- Moving the function as to where the data is called around throughout my project.
- sending the data over to draw as a parameter
- changing the parameters ( name and function calls --> seems silly but one does what one can)
- I tried moving the background call but it is essential that it remains in draw for the rest of my project to display correctly.
As i receive data form sockets, the data from the other browser is received correctly but the data from the “own” is set to undefined.
I have no clue as to why but since it is the other ship i wanted to display i went along and filtered the undefined data out.
I’ve uploaded a screenshot of my project running with the console open. As you can see here the x-data from the other browser is displayed.
How do I manipulate it so that the background does not override this data?
Below you can see a screenshot of newDrawing function (which is displaying the x in the console but is not showing the rectangle)
Only p5.js and socket.io are used in this project.
I would sincerely like to know how i can make my dreams happen and as to why this problem is tearing my brain into pieces.
Any advice would be much appreciated!