Author Topic: Axe Loops not Working as Expected  (Read 3407 times)

0 Members and 1 Guest are viewing this topic.

Offline Ki1o

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 119
  • Rating: +5/-2
  • Doing my best...
    • View Profile
Axe Loops not Working as Expected
« on: December 09, 2021, 07:26:50 pm »
I am working on a basic debugger for procedurally generated floors for my roguelike project. However, I am running into a recurring issue that I am not sure how to fix, let alone what the cause may be. I am hoping that someone with a bit more knowledge on Axe can tell me what I am doing wrong, or if there is simply an issue with Axe or the calculator.

What I am attempting to do simply generate 9 rooms and take a look at the values of the room to see if they are acceptable. However I keep randomly getting stuck in a loop either when the program executes, or when I try to give it any input. Here is the full source:

Code: [Select]
.G
L₄+22→→°RoomStart
L₄+24→→°RoomWidth
L₄+26→→°RoomHeight
L₄+28→→°RoomX
L₄+30→→°RoomY
L₄+32→→°NewRoomX
L₄+34→→°NewRoomY
L₄+36→→°Invalid
L₄+38→→°UR
L₄+40→→°LL
L₄+42→→°NewRoomX2
L₄+44→→°NewRoomY2
L₄+20→→°Rooms
Fill(L₁,36,0)
0→Rooms→RoomX→RoomY→RoomHeight→RoomWidth
ClrDraw
GenFloor()
CheckFloor()
Main()
Lbl Main
While 1
Input()
EndIf getKey(15)
Return
Lbl CheckFloor
For(J,1,Rooms)
J*4+L₁-4→Z
J+(J*((J>0)*4))-4→Y
DrawText(1,Y,"(")
DrawInt(4,Y,{Z})
DrawText(13,Y,",")
DrawInt(16,Y,{Z+1})
DrawText(24,Y,")")
DrawInt(29,Y,{Z+2})
DrawInt(38,Y,{Z+3})
End
Return
Lbl GenFloor
While Rooms<9
GenRoom()
PlaceRoom()
End
Return
Lbl GenRoom
GetRoomStart()
While 1
GetRoomSide()→RoomWidth
End!If ChkRoomWidth()
While 1
GetRoomSide()→RoomHeight
End!If ChkRoomHeight()
Return
Lbl PlaceRoom
If Rooms<9
RoomY+RoomHeight-1→{RoomX+RoomWidth-1→{RoomY→{RoomX→{Rooms+1→Rooms*4+L₁-4}+1}+1}+1}
End
Return
Lbl GetRoomStart
6+(rand^(33))→RoomX
4+(rand^(40))→RoomY
Return
Lbl GetRoomSide
4+(rand^(9))
Return
Lbl ChkRoomWidth
(RoomX+RoomWidth-1>41)
Return
Lbl ChkRoomHeight
(RoomY+RoomHeight-1>43)
Return
Lbl DrawText
For(I,0,length(r₃)-1)
conj({r₃+I}-32*4+°CharSprites,L₄+50,4)
Fill(L₄+54,4,0)
DrawChar()
End
Return
Lbl DrawInt
r₃/10+16→{L₅}
r₃^10+16→{L₅+1}
For(I,0,1)
conj({L₅+I}*4+°CharSprites,L₄+50,4)
Fill(L₄+54,4,0)
DrawChar()
End
Return
Lbl DrawChar
Pt-On(r₁+(I*((I>0)*4)),r₂,L₄+50)
Return
Lbl Input
If getKey(9)
ClrDraw
0→Rooms
GenFloor()
End
Return
[]→°CharSprites
[0000000080800080]
[A0A00000A0E0E0A0]
[60C060C0A060C0A0]
[40A060E040400000]
[4080804040202040]
[A040A0000040E040]
[000040800000E000]
[0000008000204080]
[E0A0A0E0C04040E0]
[E020C0E0E06020E0]
[A0A0E020E08060E0]
[E080E0E0E0204040]
[E0A0E0E0E0A0E020]
[4000400040004080]
[0020402000E000E0]
[00804080E0200040]
[40A0E04060A0E0A0]
[C0E0A0E0E08080E0]
[C0A0A0E0E0C080E0]
[E0C08080E080A0C0]
[A0E0A0A0E04040E0]
[6020A040A0C0A0A0]
[808080E0E0E0A0A0]
[C0A0A0A0C0A0A060]
[C0A0E080E0A0E040]
[C0A0C0A0E08020E0]
[E0404040A0A0A060]
[A0A0A040A0A0E0E0]
[A040A0A0A0A04040]
[E02080E000000000]

The results are never consistent. Sometimes it runs perfectly and it outputs the data I want, but it doesn't update the screen with the new screen data. Exiting the loop works. Sometimes it does nothing. Just freezes up. And other times it outputs the data but is completely unresponsive. If anyone wants to look through the above and give their insights that would be greatly appreciated. Thanks.

Offline Xeda112358

  • they/them
  • Moderator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 4704
  • Rating: +719/-6
  • Calc-u-lator, do doo doo do do do.
    • View Profile
Re: Axe Loops not Working as Expected
« Reply #1 on: December 09, 2021, 07:39:39 pm »
The code is difficult to follow, but it looks like you are mixing 0-indexing and 1-indexing.
You loop J from 1 to Rooms, but then you are checking if J>0 in the same loop (which is always true).

J+(J*((J>0)*4))-4→Y
Simplifies to:
J+(J*(1*4))-4→Y
J+(J*4)-4→Y
J*5-4→Y

Maybe there is something there?

Offline Ki1o

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 119
  • Rating: +5/-2
  • Doing my best...
    • View Profile
Re: Axe Loops not Working as Expected
« Reply #2 on: December 09, 2021, 08:08:20 pm »
Thanks for the optimization, however even with that change there wasn't any change at all. Sorry if its hard to follow, that's the unformatted tokenized text. Perhaps this would be a bit more readable:
Code: [Select]
.G
L4+22->->°RoomStart
L4+24->->°RoomWidth
L4+26->->°RoomHeight
L4+28->->°RoomX
L4+30->->°RoomY
L4+32->->°NewRoomX
L4+34->->°NewRoomY
L4+36->->°Invalid
L4+38->->°UR
L4+40->->°LL
L4+42->->°NewRoomX2
L4+44->->°NewRoomY2
L4+20->->°Rooms
Fill(L1,36,0)
0->Rooms->RoomX->RoomY->RoomHeight->RoomWidth
ClrDraw
GenFloor()
CheckFloor()
Main()
Lbl Main
While 1
DispGraph
Input()
EndIf getKey(15)
Return
Lbl CheckFloor
For(J,1,Rooms)
J*4+L1-4->Z
J*5-4->Y
DrawText(1,Y,"(")
DrawInt(4,Y,{Z})
DrawText(13,Y,",")
DrawInt(16,Y,{Z+1})
DrawText(24,Y,")")
DrawInt(29,Y,{Z+2})
DrawInt(38,Y,{Z+3})
End
Return
Lbl GenFloor
While Rooms<9
GenRoom()
PlaceRoom()
End
Return
Lbl GenRoom
GetRoomStart()
While 1
GetRoomSide()->RoomWidth
End!If ChkRoomWidth()
While 1
GetRoomSide()->RoomHeight
End!If ChkRoomHeight()
Return
Lbl PlaceRoom
If Rooms<9
RoomY+RoomHeight-1->{RoomX+RoomWidth-1->{RoomY->{RoomX->{Rooms+1->Rooms*4+L1-4}+1}+1}+1}
End
Return
Lbl GetRoomStart
6+(rand^(33))->RoomX
4+(rand^(40))->RoomY
Return
Lbl GetRoomSide
4+(rand^(9))
Return
Lbl ChkRoomWidth
(RoomX+RoomWidth-1>41)
Return
Lbl ChkRoomHeight
(RoomY+RoomHeight-1>43)
Return
Lbl DrawText
For(I,0,length([r3])-1)
Copy({[r3]+I}-32*4+°CharSprites,L4+50,4)
Fill(L4+54,4,0)
DrawChar()
End
Return
Lbl DrawInt
[r3]/10+16->{L5}
[r3]^10+16->{L5+1}
For(I,0,1)
Copy({L5+I}*4+°CharSprites,L4+50,4)
Fill(L4+54,4,0)
DrawChar()
End
Return
Lbl DrawChar
Pt-On([r1]+(I*((I>0)*4)),[r2],L4+50)
Return
Lbl Input
If getKey(9)
ClrDraw
0->Rooms
GenFloor()
End
Return
[]->°CharSprites
[0000000080800080]
[A0A00000A0E0E0A0]
[60C060C0A060C0A0]
[40A060E040400000]
[4080804040202040]
[A040A0000040E040]
[000040800000E000]
[0000008000204080]
[E0A0A0E0C04040E0]
[E020C0E0E06020E0]
[A0A0E020E08060E0]
[E080E0E0E0204040]
[E0A0E0E0E0A0E020]
[4000400040004080]
[0020402000E000E0]
[00804080E0200040]
[40A0E04060A0E0A0]
[C0E0A0E0E08080E0]
[C0A0A0E0E0C080E0]
[E0C08080E080A0C0]
[A0E0A0A0E04040E0]
[6020A040A0C0A0A0]
[808080E0E0E0A0A0]
[C0A0A0A0C0A0A060]
[C0A0E080E0A0E040]
[C0A0C0A0E08020E0]
[E0404040A0A0A060]
[A0A0A040A0A0E0E0]
[A040A0A0A0A04040]
[E02080E000000000]
Still not sure what's causing the bug let alone where to begin. I've changed the loop from a while loop to a repeat loop and there still was no change. What makes this all the more frustrating is that this exact structure and code works in another program. Somehow this program alone is having issues and I'm not sure why that would even be the case. Maybe Axe is just bugged? I don't feel like that's the case since many people have created vastly more complicated projects than this and I have yet to see anything about loops simply not working/crashing.