Got questions? Got answers? Go here for both.
Moderator: MaxCoderz Staff
DarkerLine
Calc Wizard
Posts: 526 Joined: Tue 08 Mar, 2005 1:37 am
Location: who wants to know?
Contact:
Post
by DarkerLine » Mon 28 Nov, 2005 9:39 pm
pacHa wrote:
This might work, if my basic memories are good (assuming Ans != 21 before this)
Since it's a repeat loop, it doesn't matter if Ans is 21 before it. Not that it matters *points to kalan's post*
If you want to wait for more than one key,
or if you want to know which key was pressed afterwards,
and the keypress will be stored in Ans afterwards.
waeV
New Member
Posts: 74 Joined: Wed 23 Apr, 2008 12:52 am
Location: Maine
Post
by waeV » Sun 14 Dec, 2008 1:10 am
I don't know if something like this has been posted, but I used this in my Tron Basic program and it sped up quite a lot:
instead of
Code: Select all
getkey -> g
if g = 24
then
...
end
if g = 25
then
...
end
I did this
Code: Select all
getkey -> g
if g != 0
if g = 24
then
...
end
if g = 25
then
...
end
end
The only problem is that the game slows down when you hold a key, as it goes through all the if statements.
My ethicator machine must have had a built-in moral compromise spectral release phantasmatron! I'm a genius!
tr1p1ea
Maxcoderz Staff
Posts: 4141 Joined: Thu 16 Dec, 2004 10:06 pm
Location: I cant seem to get out of this cryogenic chamber!
Contact:
Post
by tr1p1ea » Sun 14 Dec, 2008 3:47 am
Some people optimise their keypress blocks depending on what you need to do. If you only need to increase/decrease an x/y you can just factor in key checks.
Code: Select all
getKey->K
X+(K=26)-(K=24)->X
Y+(K=34)-(K=25)->Y
"My world is Black & White. But if I blink fast enough, I see it in Grayscale."
waeV
New Member
Posts: 74 Joined: Wed 23 Apr, 2008 12:52 am
Location: Maine
Post
by waeV » Sun 14 Dec, 2008 4:55 am
Huh, I didn't know you could do that. How would you get it to continue in the direction of the keypress without needing to be held down?
My ethicator machine must have had a built-in moral compromise spectral release phantasmatron! I'm a genius!
tr1p1ea
Maxcoderz Staff
Posts: 4141 Joined: Thu 16 Dec, 2004 10:06 pm
Location: I cant seem to get out of this cryogenic chamber!
Contact:
Post
by tr1p1ea » Sun 14 Dec, 2008 5:08 am
Guess you could:
Code: Select all
getKey
If Ans:Ans->K
X+(K=26)-(K=24)->X
Y+(K=34)-(K=25)->Y
"My world is Black & White. But if I blink fast enough, I see it in Grayscale."
waeV
New Member
Posts: 74 Joined: Wed 23 Apr, 2008 12:52 am
Location: Maine
Post
by waeV » Sun 14 Dec, 2008 6:26 am
Awesome, that works and keeps the speed fast even when a key is held.
However, I had no idea something like this could be done and still barely understand : does. Where can I read up on this sort of stuff?
I also wanted a variable F that switches between -1 and 1 when 2nd is pressed, an I came up with the following code:
Oh wait, when I do that it keeps putting 21 in as the last pressed key instead of the direction. Hmm...
My ethicator machine must have had a built-in moral compromise spectral release phantasmatron! I'm a genius!
tr1p1ea
Maxcoderz Staff
Posts: 4141 Joined: Thu 16 Dec, 2004 10:06 pm
Location: I cant seem to get out of this cryogenic chamber!
Contact:
Post
by tr1p1ea » Sun 14 Dec, 2008 6:39 am
You could try:
Code: Select all
getKey
If Ans and Ans!=21:Ans->K
F*(-2*(Ans=21)+1)->F
X+(K=26)-(K=24)->X
Y+(K=34)-(K=25)->Y
"My world is Black & White. But if I blink fast enough, I see it in Grayscale."
waeV
New Member
Posts: 74 Joined: Wed 23 Apr, 2008 12:52 am
Location: Maine
Post
by waeV » Sun 14 Dec, 2008 6:47 am
Well, now it won't accept 2nd as input.
Does the ":" equate to a "then"?
My ethicator machine must have had a built-in moral compromise spectral release phantasmatron! I'm a genius!
tr1p1ea
Maxcoderz Staff
Posts: 4141 Joined: Thu 16 Dec, 2004 10:06 pm
Location: I cant seem to get out of this cryogenic chamber!
Contact:
Post
by tr1p1ea » Sun 14 Dec, 2008 8:00 am
: is the character ':', accessed via Alpha+'.' also the " and " is accessed via 2nd+MATH>LOGIC.
"My world is Black & White. But if I blink fast enough, I see it in Grayscale."
kalan_vod
Calc King
Posts: 2932 Joined: Sat 18 Dec, 2004 6:46 am
Contact:
Post
by kalan_vod » Sun 14 Dec, 2008 8:51 am
The ":" is just as if you make a new line, but this just helps when you want to group routines in one area. It is not any faster/slower than creating a new line, it really is just a matter of opinion..I love to use it, as it makes things easier to read.
If you are wanting to know more about basic, I would suggest going to
TI|BD .
waeV
New Member
Posts: 74 Joined: Wed 23 Apr, 2008 12:52 am
Location: Maine
Post
by waeV » Sun 14 Dec, 2008 11:35 pm
Thanks for the link.
I am confused, though, I am used to the following syntax:
Code: Select all
if ans != 0 and ans !=21
then
ans -> k
end
If : is just the same as a new line, then what how come the following doesn't need a then, an end, or a logic operator for the first comparison?
My ethicator machine must have had a built-in moral compromise spectral release phantasmatron! I'm a genius!
calc84maniac
Regular Member
Posts: 112 Joined: Wed 18 Oct, 2006 7:34 pm
Location: The ex-planet Pluto
Contact:
Post
by calc84maniac » Mon 15 Dec, 2008 1:15 am
"If" only needs a "Then" and "End" if it needs more than one line of code to run if true (colon counts as a newline).
~calc84maniac has spoken.
Projects:
F-Zero 83+
Project M (Super Mario for 83+)
waeV
New Member
Posts: 74 Joined: Wed 23 Apr, 2008 12:52 am
Location: Maine
Post
by waeV » Mon 15 Dec, 2008 1:59 am
Well that make for much cleaner code, thanks. I remember you could do something like that in QBASIC but not in Ti-Basic.
So are the following equivalent?
My ethicator machine must have had a built-in moral compromise spectral release phantasmatron! I'm a genius!
benryves
Maxcoderz Staff
Posts: 3089 Joined: Thu 16 Dec, 2004 10:06 pm
Location: Croydon, England
Contact:
Post
by benryves » Mon 15 Dec, 2008 2:24 am
Non-zero is implicitly true.
waeV
New Member
Posts: 74 Joined: Wed 23 Apr, 2008 12:52 am
Location: Maine
Post
by waeV » Mon 15 Dec, 2008 3:51 am
Ah, I get it.
Sweet, this will help a ton.
My ethicator machine must have had a built-in moral compromise spectral release phantasmatron! I'm a genius!