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

0 Members and 1 Guest are viewing this topic.

Ki1o

• LV4 Regular (Next: 200)
• Posts: 104
• Rating: +5/-2
• Doing my best...
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]
.GL₄+22→→°RoomStartL₄+24→→°RoomWidthL₄+26→→°RoomHeightL₄+28→→°RoomXL₄+30→→°RoomYL₄+32→→°NewRoomXL₄+34→→°NewRoomYL₄+36→→°InvalidL₄+38→→°URL₄+40→→°LLL₄+42→→°NewRoomX2L₄+44→→°NewRoomY2L₄+20→→°RoomsFill(L₁,36,0)0→Rooms→RoomX→RoomY→RoomHeight→RoomWidthClrDrawGenFloor()CheckFloor()Main()Lbl MainWhile 1Input()EndIf getKey(15)ReturnLbl CheckFloorFor(J,1,Rooms)J*4+L₁-4→ZJ+(J*((J>0)*4))-4→YDrawText(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})EndReturnLbl GenFloorWhile Rooms<9GenRoom()PlaceRoom()EndReturnLbl GenRoomGetRoomStart()While 1GetRoomSide()→RoomWidthEnd!If ChkRoomWidth()While 1GetRoomSide()→RoomHeightEnd!If ChkRoomHeight()ReturnLbl PlaceRoomIf Rooms<9RoomY+RoomHeight-1→{RoomX+RoomWidth-1→{RoomY→{RoomX→{Rooms+1→Rooms*4+L₁-4}+1}+1}+1}EndReturnLbl GetRoomStart6+(rand^(33))→RoomX4+(rand^(40))→RoomYReturnLbl GetRoomSide4+(rand^(9))ReturnLbl ChkRoomWidth(RoomX+RoomWidth-1>41)ReturnLbl ChkRoomHeight(RoomY+RoomHeight-1>43)ReturnLbl DrawTextFor(I,0,length(r₃)-1)conj({r₃+I}-32*4+°CharSprites,L₄+50,4)Fill(L₄+54,4,0)DrawChar()EndReturnLbl DrawIntr₃/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()EndReturnLbl DrawCharPt-On(r₁+(I*((I>0)*4)),r₂,L₄+50)ReturnLbl InputIf getKey(9)ClrDraw0→RoomsGenFloor()EndReturn[]→°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.

Xeda112358

• they/them
• Moderator
• LV12 Extreme Poster (Next: 5000)
• Posts: 4688
• Rating: +718/-6
• Calc-u-lator, do doo doo do do do.
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?

Ki1o

• LV4 Regular (Next: 200)
• Posts: 104
• Rating: +5/-2
• Doing my best...
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]
.GL4+22->->°RoomStartL4+24->->°RoomWidthL4+26->->°RoomHeightL4+28->->°RoomXL4+30->->°RoomYL4+32->->°NewRoomXL4+34->->°NewRoomYL4+36->->°InvalidL4+38->->°URL4+40->->°LLL4+42->->°NewRoomX2L4+44->->°NewRoomY2L4+20->->°RoomsFill(L1,36,0)0->Rooms->RoomX->RoomY->RoomHeight->RoomWidthClrDrawGenFloor()CheckFloor()Main()Lbl Main While 1 DispGraph Input() EndIf getKey(15)ReturnLbl 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}) EndReturnLbl GenFloor While Rooms<9 GenRoom() PlaceRoom() EndReturnLbl GenRoom GetRoomStart() While 1 GetRoomSide()->RoomWidth End!If ChkRoomWidth() While 1 GetRoomSide()->RoomHeight End!If ChkRoomHeight()ReturnLbl PlaceRoom If Rooms<9 RoomY+RoomHeight-1->{RoomX+RoomWidth-1->{RoomY->{RoomX->{Rooms+1->Rooms*4+L1-4}+1}+1}+1} EndReturnLbl GetRoomStart 6+(rand^(33))->RoomX 4+(rand^(40))->RoomYReturnLbl GetRoomSide 4+(rand^(9))ReturnLbl ChkRoomWidth (RoomX+RoomWidth-1>41)ReturnLbl ChkRoomHeight (RoomY+RoomHeight-1>43)ReturnLbl DrawText For(I,0,length([r3])-1) Copy({[r3]+I}-32*4+°CharSprites,L4+50,4) Fill(L4+54,4,0) DrawChar() EndReturnLbl 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() EndReturnLbl DrawChar Pt-On([r1]+(I*((I>0)*4)),[r2],L4+50)ReturnLbl Input If getKey(9) ClrDraw 0->Rooms GenFloor() EndReturn[]->°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.