math not working as expected.
Asked Answered
J

2

0

I'm making a top-down rogue with dungeon generation similar to the binding of Isaac. I'm trying to make a system to be able to tell which room the players in, I create doors on each side of a room and give each a direction, I have it, so it increments the pos_x or pos_y by 1/-1 depending on the direction of the door the player enters (1 is to the right, 2 is down, etc). I want it so for example if pos_x = 4 and you were to enter a door with direction = 3 it would -1 from pos_x making it 3, but as of now it just sets pos_x to -1. each door can increment fine, so if I keep entering a door with direction = 1 it will continue to increase pos_x by 1, but it messes up if I try to go the opposite direction.

I feel like my math is right, but I could be making a dumb mistake, any help appreciated.

Joint answered 29/11, 2023 at 17:47 Comment(0)
P
0

Joint What is the output if you put a prints(pos_x, pos_y) at the top of the function?

and you were to enter a door with direction = 3 it would -1 from pos_x making it 3, but as of now it just sets pos_x to -1

That makes it sound like pos_x gets reset to 0 at some point. Where do you initialize pos_x/y and do you update them somewhere in between? I think you need to show some more surrounding code or your scene structure.

Palaeontography answered 29/11, 2023 at 17:55 Comment(0)
J
0

Palaeontography yeah, I just found the issue I was instancing each door, so each doors variable was separate from the others.

Joint answered 29/11, 2023 at 18:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.