Author Topic: Variable locations?  (Read 5866 times)

0 Members and 1 Guest are viewing this topic.

Offline dinosteven

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 194
  • Rating: +10/-1
    • View Profile
Variable locations?
« on: December 26, 2012, 12:30:17 pm »
I have this:
{S}^5->C
{S}/5->D
{S+1}^5->E
{S+1}/5->F
{S+2}^5->G
{S+2}/5->H
{S+3}^5->I
{S+3}/5->J
.......on until {S+7}/5->R.
There's gotta be a way to optimize this; I know the variables are in some memory location... Can someone explain how to do this?
« Last Edit: December 26, 2012, 12:49:53 pm by dinosteven »

Offline Runer112

  • Project Author
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2289
  • Rating: +639/-31
    • View Profile
Re: Variable locations?
« Reply #1 on: December 26, 2012, 02:03:55 pm »
Hold onto your pants.

Code: [Select]
°S→A
8
While 1
End!If Select(-1,Select({+S},*2/10Store())^5Store())

Lbl Store
→{A-2→A}ʳ
Return

If speed is important and you want to avoid the /10 B_CALL and doing both a divide and a modulus operation:

Code: [Select]
°S→A
8
While 1
End!If Select(-1,{+S}-(Select(/5,Store())*5)Store())

Lbl Store
→{A-2→A}ʳ
Return


EDIT: I do hope these actually work; I didn't test them.

EDIT 2: Now I did test them, fixed a small issue with the second one and now they both work.
« Last Edit: December 27, 2012, 08:34:42 pm by Runer112 »

Offline dinosteven

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 194
  • Rating: +10/-1
    • View Profile
Re: Variable locations?
« Reply #2 on: December 26, 2012, 04:11:48 pm »
How are you using "Select()" and "Store()"? I don't understand...

Offline Runer112

  • Project Author
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2289
  • Rating: +639/-31
    • View Profile
Re: Variable locations?
« Reply #3 on: December 26, 2012, 06:34:32 pm »
Select(EXPR1,EXPR2) is an optimized way (only 2 bytes!) of saving the value of EXPR1, then evaluating EXPR2, then restoring the value of EXPR1. The first Select(-1,blah) decrements one from the loop counter, which goes from 3 to 0, and then saves it while we do the actual work. The next Select({+S},blah) adds the loop counter to S, reads the value at that memory location, and saves it; this is so we can use it for the ^5 later, while we can also use it for *2/10 now. Each call to the Store() command stores the 2-byte value before it to the previous letter variable (starting with S/R), and because of how we ordered our calls to it, we store the value divided by 5 first to the later letter variable, and then the value modulo 5 second to the letter variable right before it.

Offline dinosteven

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 194
  • Rating: +10/-1
    • View Profile
Re: Variable locations?
« Reply #4 on: December 27, 2012, 08:06:35 am »
Ok... didn't know you could create commands like that! Is the -1 a negative sign or a minus sign?
I used a minus sign (probably wrong); and when compiling, Axe 1.1.2 gave me "ERROR: WRONG # OF ARGS" and proceeded to crash. (This has been a recurring problem with my Axe; upon finding compile errors, it screws up my calc.)
« Last Edit: December 27, 2012, 08:40:04 am by dinosteven »

Offline Hayleia

  • Programming Absol
  • Coder Of Tomorrow
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3367
  • Rating: +393/-7
    • View Profile
Re: Variable locations?
« Reply #5 on: December 27, 2012, 08:49:35 am »
Yes, it is a minus sign, like in 1-1=0. About your error, are you sure you put the "," after the "-1" ?
I own: 83+ ; 84+SE ; 76.fr ; CX CAS ; Prizm ; 84+CSE
Sorry if I answer with something that seems unrelated, English is not my primary language and I might not have understood well. Sorry if I make English mistakes too.

click here to know where you got your last +1s

Offline dinosteven

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 194
  • Rating: +10/-1
    • View Profile
Re: Variable locations?
« Reply #6 on: December 27, 2012, 06:30:54 pm »
Ok. I did it again, but something's not right. With a Data(18,24,16,9,6,8,15,19) - locations on a 5x5 grid, I extracted that from appvar to S to the variables.
But only the second one (24) is correct, and it looks like (it's an amalgam of sprites on top of each other) everything else is on 6 and 18.

Offline Runer112

  • Project Author
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2289
  • Rating: +639/-31
    • View Profile
Re: Variable locations?
« Reply #7 on: December 27, 2012, 08:10:00 pm »
It seems to work fine when I run it; given Data(18,24,16,9,6,8,15,19)→S, I get:

  • C: 3
  • D: 3
  • E: 4
  • F: 4
  • G: 1
  • H: 3
  • I: 4
  • J: 1
  • K: 1
  • L: 1
  • M: 3
  • N: 1
  • O: 0
  • P: 3
  • Q: 4
  • R: 3

Are you sure you copied the code correctly? I can understand copying it incorrectly because the code is a little strange.
« Last Edit: December 27, 2012, 08:10:45 pm by Runer112 »

Offline leafy

  • CoT Emeritus
  • LV10 31337 u53r (Next: 2000)
  • *
  • Posts: 1554
  • Rating: +475/-97
  • Seizon senryakuuuu!
    • View Profile
    • keff.me
Re: Variable locations?
« Reply #8 on: December 27, 2012, 08:17:35 pm »
In addition, it'd be nice if you posted your sprite drawing code so we can make sure something's not off there.
In-progress: Graviter (...)

Offline dinosteven

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 194
  • Rating: +10/-1
    • View Profile
Re: Variable locations?
« Reply #9 on: December 27, 2012, 08:30:28 pm »
Yeah, should've got a camera... Anyways, I had the second one copied; I tried Runner's 1st code and it worked. Thanks for the help!

Offline Runer112

  • Project Author
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2289
  • Rating: +639/-31
    • View Profile
Re: Variable locations?
« Reply #10 on: December 27, 2012, 08:37:54 pm »
My bad, I had a parenthesis issue with the second one. That's one of the reasons why I'm still not happy that Axe allows you to leave parentheses unclosed like TI-BASIC, otherwise it would have thrown an error and I would have caught it more easily.

Offline dinosteven

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 194
  • Rating: +10/-1
    • View Profile
Re: Variable locations?
« Reply #11 on: December 29, 2012, 02:04:27 pm »
Ok, I have another thing I need to optimize. (idk why I named the topic var locations, the solution had nothing to do with that, and it really is just for optimizations that I can't do)
Code: [Select]
Pt-On(C*9+1,D*9+1,Pic1)
Pt-On(E*9+1,F*9+1,Pic1)
Pt-On(G*9+1,H*9+1,Pic2)
Pt-On(I*9+1,J*9+1,Pic2)
Pt-On(K*9+1,L*9+1,Pic3)
Pt-On(M*9+1,N*9+1,Pic3)
Pt-On(O*9+1,P*9+1,Pic4)
Pt-On(Q*9+1,R*9+1,Pic4)
I defined Pic1-Pic4 like this:
[stuff]->Pic1
[stuff]
[stuff]->Pic2
[stuff]
[stuff]->Pic3
[stuff]
[stuff]->Pic4
[stuff]