Omnimaga
Calculator Community => Major Community Projects => The Axe Parser Project => Topic started by: Okimoka on December 13, 2016, 01:06:17 pm
-
Is there a way to shorten this code?
If L=1
Pt-On(...,Pic1)
End
If L=2
Pt-On(...,Pic2)
End
If L=3
Pt-On(...,Pic3)
End
...
I tried accessing the images using memory adresses but it doesn't seem like the Pic variables have constant memory space between them.
Is there a way to evaluate an expression as a variable?
Is this already the most efficient you can get?
Thank you for your help!
-
Well, you could do something like
Pt-On(....,L=1?Pic1,(L=2?Pic2,(L=3?Pic3))))
Or, preferable, probably a pointer-table, however it slipped my mind right now how to do those in axe....
If you are wondering what that question-mark stuff does: https://derpybot.sorunome.de/axe.php?q=%3F (https://derpybot.sorunome.de/axe.php?q=%3F)
-
Very nice, the ternary solution is already so much cleaner!
If I understood right, a pointer-table would require me to write the adresses of all Pic variables into a Buffer first?
-
You can do this by writing the addresses of the three sprites into a buffer, yes. The code would look something like this:
Pt-On(X,Y,{L*2-2+Data(Pic1ʳ,Pic2ʳ,Pic3ʳ)}ʳ)
However, best would be to declare the sprite data in sequence so each one's data immediately follows the next, which allows this:
[0123456789ABCDEF]→Pic1
[FEDCBA9876543210]→Pic2
[FFFFFFFFFFFFFFFF]→Pic3
...
other stuff here
...
Pt-On(X,Y,L*8-8+Pic1)
And a suggestion: in either case, your life would be made easier by using zero-based numbering. That generally translates into simpler/more efficient code. In the first case, you could remove the -2, and in the second case, you could remove the -8.
-
Works fantastically, thank you both so much for your time!
I revised the program to use zero-indexing, good hint :thumbsup:
-
You can do this by writing the addresses of the three sprites into a buffer, yes. The code would look something like this:
Pt-On(X,Y,{L*2-2+Data(Pic1ʳ,Pic2ʳ,Pic3ʳ)}ʳ)
However, best would be to declare the sprite data in sequence so each one's data immediately follows the next, which allows this:
[0123456789ABCDEF]→Pic1
[FEDCBA9876543210]→Pic2
[FFFFFFFFFFFFFFFF]→Pic3
...
other stuff here
...
Pt-On(X,Y,L*8-8+Pic1)
And a suggestion: in either case, your life would be made easier by using zero-based numbering. That generally translates into simpler/more efficient code. In the first case, you could remove the -2, and in the second case, you could remove the -8.
You actually only have to name the first block, so that your code looks like this (assuming now you have zero-based numbering):
[0123456789ABCDEF]→Pic1
[FEDCBA9876543210
[FFFFFFFFFFFFFFFF
...
other stuff here
...
Pt-On(X,Y,L*8+Pic1)