Author Topic: Compare getkey to a list  (Read 18085 times)

0 Members and 1 Guest are viewing this topic.

Offline TIfanx1999

  • ಠ_ಠ ( ͡° ͜ʖ ͡°)
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 6173
  • Rating: +191/-9
    • View Profile
Compare getkey to a list
« on: January 24, 2010, 02:52:30 am »
It's been quite a while since I've done any programming, but I seem to remember that there was a way to use the cumSum or seq( command to compare the keypress values in getkey to a list of elements. Can anyone confirm/deny this and post some code if it's possible?

Offline {AP}

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 981
  • Rating: +74/-3
  • I am Webmaster!
    • View Profile
    • Removed From Game
Re: Compare getkey to a list
« Reply #1 on: January 24, 2010, 03:38:41 am »
Hm... I think I know what code you're talking about.
Though, I have to ask you to elaborate a bit. Technically, all you need to compare a keypress to a list is to type "getkey→K:K=<insert a list here>".

So, because of that, I need to know something like what you'll use this for then I can probably give you example code for that and explain it, if need be.

Offline TIfanx1999

  • ಠ_ಠ ( ͡° ͜ʖ ͡°)
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 6173
  • Rating: +191/-9
    • View Profile
Re: Compare getkey to a list
« Reply #2 on: January 24, 2010, 03:46:39 am »
It was something along the lines of:

Repeat getkey=cumSum(24,25,26,34
End
Supposedly it was the fastest way to compare a keypress to a list of numbers instead of doing something horribly inefficient like:

Repeat getkey= 24 or getkey=25 or getkey=26 or getkey=34
End

Offline {AP}

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 981
  • Rating: +74/-3
  • I am Webmaster!
    • View Profile
    • Removed From Game
Re: Compare getkey to a list
« Reply #3 on: January 24, 2010, 03:56:34 am »
Well, for that, it'd just be...

Repeat sum(getKey={24,25,26,34
End

For example, if getKey was 25 the "getkey={24,25,26,34" part would output "{0,1,0,0}" then the "sum(" would add the elements together to equal "1" or "TRUE".

If it was cumSum then it'd output "{0,1,1,1}" in the end, which isn't a boolean as required by the Repeat function.

Offline TIfanx1999

  • ಠ_ಠ ( ͡° ͜ʖ ͡°)
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 6173
  • Rating: +191/-9
    • View Profile
Re: Compare getkey to a list
« Reply #4 on: January 24, 2010, 04:07:35 am »
It works, thanks! =D I wonder why i was remembering cumSum I dunno, it was something about a discussion of doing this with the best possible speed....I'm probably just remembering wrong. I sure am rusty XD
« Last Edit: January 24, 2010, 04:08:52 am by Art_of_camelot »

Offline {AP}

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 981
  • Rating: +74/-3
  • I am Webmaster!
    • View Profile
    • Removed From Game
Re: Compare getkey to a list
« Reply #5 on: January 24, 2010, 04:09:09 am »
Haha, no problem!

I'm pretty rusty myself.
Had to actually test it on my calc first just to make sure I gave you the right information. ^^

(And I'm not sure that it's the fastest... but it's a hell of a lot faster and smaller than typing out "getKey=#" for each on you want to check. =P )
« Last Edit: January 24, 2010, 04:11:48 am by {AP} »

Offline TIfanx1999

  • ಠ_ಠ ( ͡° ͜ʖ ͡°)
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 6173
  • Rating: +191/-9
    • View Profile
Re: Compare getkey to a list
« Reply #6 on: January 24, 2010, 04:46:21 am »
After some looking I found the routines I was originally trying to remember. The original did indeed use sum, (not cumSum) but the one that was recommended as being the fastest was with the max command.
IE:

Repeat max(getKey={24,25,26,34
End

Offline ztrumpet

  • The Rarely Active One
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5712
  • Rating: +364/-4
  • If you see this, send me a PM. Just for fun.
    • View Profile
Re: Compare getkey to a list
« Reply #7 on: January 24, 2010, 10:57:04 am »
Remember that if you want to use the keypress you'd need to do this:

Repeat max(Ans={24,25,26,34
getKey->K //You don't need to store it to K, but I usually do. :)
End

Offline Silver Shadow

  • Beta Tester
  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 817
  • Rating: +27/-7
    • View Profile
Re: Compare getkey to a list
« Reply #8 on: January 24, 2010, 11:40:28 am »
Hmmm... I think I'll use this code... I've never thought of doing the keypress detection that way...
Thanks for helping me discover something new!
Former Coder of Tomorrow


Offline TIfanx1999

  • ಠ_ಠ ( ͡° ͜ʖ ͡°)
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 6173
  • Rating: +191/-9
    • View Profile
Re: Compare getkey to a list
« Reply #9 on: January 24, 2010, 05:21:44 pm »
@Ztrumpet, well yea that should go without saying. :) Funfact: The convention of using K for getkey started because that was what the example in TI's manual used. The same goes for using the variable I as the default variable in For loops.  ;D

@Silver Shadow:Great! It's a quick and simple way to do it. =D
« Last Edit: January 24, 2010, 05:28:24 pm by Art_of_camelot »

Offline ztrumpet

  • The Rarely Active One
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5712
  • Rating: +364/-4
  • If you see this, send me a PM. Just for fun.
    • View Profile
Re: Compare getkey to a list
« Reply #10 on: January 24, 2010, 06:37:37 pm »
The convention of using K for getkey started because that was what the example in TI's manual used.
Ah, I think that's why I use it.  I never realized that. ;D

Offline {AP}

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 981
  • Rating: +74/-3
  • I am Webmaster!
    • View Profile
    • Removed From Game
Re: Compare getkey to a list
« Reply #11 on: January 24, 2010, 06:55:30 pm »
Funfact: The convention of using K for getkey started because that was what the example in TI's manual used.

Really? I just used it because to me K = Keypress. I do that with variables a lot. Like Position in a menu = M or any temporary variable = X.
In fact... I never even read the TI manual. =D

Though, you're probably right for the most part. I'm always a weird exception it seems. =P

Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: Compare getkey to a list
« Reply #12 on: January 24, 2010, 07:27:46 pm »
Ha, I never looked at the manual eaither, and I use K for all my key variables XD

I use F for all my for loop vars tho O.O and G too if I have nested for loops XD

Offline TIfanx1999

  • ಠ_ಠ ( ͡° ͜ʖ ͡°)
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 6173
  • Rating: +191/-9
    • View Profile
Re: Compare getkey to a list
« Reply #13 on: January 24, 2010, 07:50:21 pm »
Alot of us (way back in the day) used the thick paperback manuals that TI used to include with their products as a stating point for programming and as a reference. Many people learned from looking at others code, and as time passed people wrote their own tutorials and used what they were familiar with as reference. Thus certain conventions were established regardless of them having any relevance. Although, I suppose "K" for key does actually make sense. I just find it interesting that some of these things have largely stayed the same since about 98/99.

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: Compare getkey to a list
« Reply #14 on: January 24, 2010, 08:21:05 pm »
I always used Z for key variable and For( loops. When a variable conflict occured I just used Theta for For( loops instead