How do I get my coordinates to show (But there's math this time)

Question: When logging, I don’t get any coords. How would I go about fixing this?


Repl link

<script type="text/javascript" src="glwindow.js"></script>
    <script type="text/javascript">
        let cvs = document.querySelector("#viewport-canvas");
	    let glwindow = new GLWindow(cvs);
        cvs.addEventListener('mousemove', function (e) {
            pos = glwindow.click({
                x: e.clientX,
                y: e.clientY
            });
            console.log(pos)
            document.getElementById("x-value").textContent = pos.x;
            document.getElementById("y-value").textContent = pos.y;
        });
    </script>

above this file, you can use ctrl + f and type in click inside glwindow.js to find the function that should be returning coordinates.

Sorry for making this the 3rd question about this project.

1 Like

The repl is private, idk if that’s how you wanted it to be.
Now knowing what glwindow.js looks like, I can’t help you any further

Did the link not work?

I saw someone join it…

I just made the entire thing public.

e is not defined, as the Console (CtrlJ) would complain.

1 Like

event is supposed to be e. Even so, it still doesn’t work.

Cannot read properties of undefined (reading 'x')

The link now works but points at a Go repl with what seems to be a hello world program.

Considering the error message, it might be possible that glwindow.click doesn’t return anything.
Perhaps consider changing this

document.getElementById("x-value").textContent = pos.x;
document.getElementById("y-value").textContent = pos.y;

into this

document.getElementById("x-value").textContent = e.clientX;
document.getElementById("y-value").textContent = e.clientY;

(re-use the variable e’s attributes)

~/NewTest/place/web/root/desktop.html

And also,

image

I’m sorry, what does this mean?

As for the undefined-s, you will still log undefined because, as said before, it seems like glwindow.click is not returning anything (hence pos will be given a value of undefined).

What should glwindow.click return? Can I have a look at the code?

That’s how you locate what I’m referring to.

Go inside the folder place → Folder web → folder root → file desktop.html

Click isn’t returning anything and that’s the problem.

1 Like

I think I found the problem. Line 168 in glwindow.js, you are returning nothing if a certain condition is met.
Where is that math coming from? Double check it

Also sorry for being rude before, I didn’t properly understand

I’m going to do what is called “a pro gamer move” and quit working on coordinates. I can’t get it to work inside that environment, but can inside previous environments.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.