Closed PyryTheBurger closed 2 years ago
i also have these methods that use it could they be the problem idk
proc updateHButtons*(hButtons: seq[Button]) =
if selectedButton == 0 and isKeyPressed(leftKey):
selectedButton = len(hButtons) - 1
elif selectedButton == len(hButtons) - 1 and isKeyPressed(rightKey):
selectedButton = 0
else:
if isKeyPressed(leftKey):
dec(selectedButton)
if isKeyPressed(rightKey):
inc(selectedButton)
if isKeyPressed(interactKey):
hButtons[selectedButton].pressed()
buttonSelected = hButtons[selectedButton]
proc drawButtons*(buttons: seq[Button]) =
for i, v in pairs(buttons):
if v == buttonSelected:
drawRectangleLinesEx(v.rect, 1, Black)
drawText(cstring(v.text), int(v.rect.x), int(v.rect.y), 1, Black)
else:
drawRectangleRec(v.rect, Black)
drawText(cstring(v.text), int(v.rect.x), int(v.rect.y), 1, White)
@PyryTheBurger could you create a minimal, self contained example code that we can run to reproduce the issue?
@PyryTheBurger I saw your answer on discord that you solved it by using ref
object instead of plain object. This changes the semantics of how things work so there are cases where you would want to have a plain object still. If you could provide us a snippet of code which clearly demonstrates the issue, we could help you with the problem you are facing.
so I have a button type with 4 variables, no problem:
and just a norrmal constructor like
button1: Button = Button(rect: (100.0, 0.0, 24.0, 24.0), text: "1", pressed: echohelloworld)
and everything works.now if i have over 4 variables like this:
1 of the variables (rect in this case idk if its random or something = (0.0, 0.0, 0.0, 0.0)) is 0 even though i construct it the same way as above