Omnimaga
Calculator Community => TI Calculators => TI-BASIC => Topic started by: TIfanx1999 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?
-
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.
-
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
-
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.
-
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
-
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 )
-
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
-
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
-
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!
-
@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
-
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
-
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
-
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
-
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.
-
I always used Z for key variable and For( loops. When a variable conflict occured I just used Theta for For( loops instead
-
I use theta and I for loops.
K for getkey, of course. I didn't know of TI examples... I just followed others.
I also use F for flags (1 or 0).
The lists I prefer to use is not L1 and L2 but L5 and L6 because is more friendly to user. You rarely use them but L1 and L2 are the first used, I suppose.
-
I usually will use K for getkey, M for menu output. A and B are my vars that I use most, along with X Y C D E F in no particular order. Although I will usually use x and Y for location variables.
-
The only bad part about everyone using K for example is that sometimes there are people who think K is the only variable that can be used with GetKey XD
-
You know what? Now that I thing about it, I might have used theta as my key variable up until I found donut quest. I totaly picked apart the source :P and so many of my games were inspired one way or anoher by different parts of DQ. Ha, even portal was a partial brainchild of DQ XD
-
You one what?
I do not understand this question.
-
Whoops, sorry about that. I'm on my itouch so a simple misspelling and it autocorrects to something else:P
-
lol, I hate that x.x
hmm, too bad I'm studying for bio, I want to play a game of eliminate x.x
-
The variables I use most are A, B, C, S, T, and K. The only variable I'll always use for something is K, so my code is probably the messyist. :P
-
Other things I remembered: I also use theta as a "temporary" variable through all code, this means, it is used once and can be destroyed later for other function.
And I have seen "I" variable used in loops in other languages like JavaScript (but in lowercase). For nested loops, "j" is used next. :P
Also X and Y are good for position but some graph functions zeroes Y or X. So I use A and B or R and C (row and column).
I try to use a variable letter as the starting name for its function. For example, "H" for health, "J" for jump, "M" for menu or magic, etc..
Oh we are offtopic but is interesting to see there is the K variable convention.
-
And I have seen "I" variable used in loops in other languages like JavaScript (but in lowercase). For nested loops, "j" is used next. :P
It's funny; In C++ I use i, j, and k for my for loops, but in Ti Basic I use A, B, and C. I'm wierd! :P
-
i think of I=Increment for loops, and thus the reason i use it in for loops :{O
i'm kind of leaning towards the approach of just using variables as i get to them in order, and saving a table defining what each variable is used for when, i think this would actually be a cleaner approach because when you get to the point where every single variable is in use/has multi-uses it begins to get very confusing and you can forget what does what so you have to create tables anyway
-
I actually use theta for getkey, and Z for repeat group, acting something like flag.
A,B for variables I use a lot. X,Y for position (sometimes not because Y tend to change when using ClrDraw)
-
Repeat max(Ans={24,25,26,34
getKey->K //You don't need to store it to K, but I usually do. :)
End
Repeat max(Ans={24,25,26,34
getKey
End
Ans-->K
Takes up an extra byte, but ought to be a bit faster
-
hmm, interesting. I'll have to remember that.
also welcome to Omnimaga rthprog.
-
@Eeems_
thanks! Omnimaga's TIBasic subforum seems a bit more active than Cemetech's (excluding John Massey, of course)
-
np
yeah it does, we have more basic programmers here that are active.
-
Hi rthprog, for some reasons when I saw your nickname on latest members I was certain you alerady signed up here before so I thought to myself: "oh crap, I accidentally deleted him in a spambot account purge x.x", but then I remembered it was Reapex who had an account. Anyway welcome here ^^
Activity-wise, we normally are more focused on calc game projects while TIBD/Cemetech are more help-oriented/non-game-oriented (and UTI an hybrid of all), but it seems there have been more activity in the help forums here lately, especially since we split TI-BASIC out of the only calc help subforum we had.
-
Repeat max(Ans={24,25,26,34
getKey->K //You don't need to store it to K, but I usually do. :)
End
Repeat max(Ans={24,25,26,34
getKey
End
Ans-->K
Takes up an extra byte, but ought to be a bit faster
Great idea! I'm sure this is faster when no key is pressed, but I don't know if it's faster when a key is pressed. It's nice code, though. ;D
Edit: Oh, and because of the new-line it takes two more bytes.
Welcome here! *ZTrumpet points rthprog towards the Introduce Yourself sub forum. :)
-
*ZTrumpet points rthprog towards the Introduce Yourself sub forum. :)
He'll be scared to death D:
-
Lol yeah, that subforum is a scary place x.x that's why I don't venture there often.
-
*ZTrumpet lols at Eeems and DJ...
The only extremely scary part is the first page of DJ's topic...
-
And you must avoid the peanuts bags being thrown from everywhere
-
I'm sure this is faster when no key is pressed, but I don't know if it's faster when a key is pressed.
Yeah, i see this optimization a lot actually, but i tend to shy away from it. I don't need speed when nothing is happening :P
Either way, welcome to Omnimaga! and look out for stray lobsters O.O
-
Lol, okay.
@Builderboy
"I don't need speed when nothing is happening"
Good point. In my defense, I'm somewhat used to leaving the "-->K" out altogether; often it is unnecessary to store the key at all.
-
That is very true :) That would be the fastest option. Or you could be totally awesome like Weregoose and use nothing but Ans for the entire program ;D
-
...I'm somewhat used to leaving the "-->K" out altogether; often it is unnecessary to store the key at all.
Right, and it's fastest if you don't have to store K. ;D
Edit: Ninjaed!
-
Haha at the risk of actually being on topic about the movement part of this I remember seeing something about movement code at TI-BASIC Developer (http://tibasicdev.wikidot.com/movement-explanation). It is supposedly faster than usual and deals with ⌂List. I'm not sure how it works, with my lack of knowledge of those commands, but thought I'd throw that out there haha.