CodeWalrus

Development => Calculators => Calculator News, Coding, Help & Talk => Topic started by: xMarminq_ on November 13, 2016, 11:24:38 PM

Title: My BASIC Questions
Post by: xMarminq_ on November 13, 2016, 11:24:38 PM
I am making a part of a game where I need two things running at once, like doing an action in a said time period.
Let me know what you would do, and will certainly help in the development. 
Title: Re: My BASIC Questions
Post by: E37 on November 13, 2016, 11:38:23 PM
I would have them take turns running. Knowing what two things would be helpful.
To answer your question, there is no way of doing two things at the exact same time at all on the calc.
Title: Re: My BASIC Questions
Post by: p2 on November 13, 2016, 11:56:08 PM
in general you can either switch between two tasks super fast or do two things after another and repeat that over and over again...
which would be Interrupts (not available in pure BASIC) or putting everything in your main loop ^^
While 1
: task 1
: task 2
: task 3
:End

btw WHILE 1 is the same as WHILE TRUE which means the condition (true) is always met ---> infinite loop :)

But before trying something fancy now, listen to E37 as there are better ways of doing many things ^^
Title: Re: My BASIC Questions
Post by: kotu on November 13, 2016, 11:59:27 PM
We really need a bit more information as.... you may have a simpler situation than described above

For example if you need to work out distance travelled for two cars, you can just multiply 'Time Passed' by Speed and there you have both distances
Title: Re: My BASIC Questions
Post by: xMarminq_ on November 14, 2016, 01:36:13 AM
Like I want someone to tap a button to get to a certain value while a timer is going off
Title: Re: My BASIC Questions
Post by: kotu on November 14, 2016, 01:42:16 AM
What you want to do is fairly simple - someone else will explain though as I don't know really any TI-BASIC
Title: Re: My BASIC Questions
Post by: xMarminq_ on November 14, 2016, 02:08:59 AM
Start mentioning people you may know who could help
Title: Re: My BASIC Questions
Post by: kotu on November 14, 2016, 02:12:54 AM
I don't know who uses TI-BASIC on here, I'm more into other languages, namely C and C++

What you want though is an infinite loop, in which you keep checking for key presses, and keep checking the timer  :P
Title: Re: My BASIC Questions
Post by: xMarminq_ on November 14, 2016, 03:17:21 AM
Any way someone can create something like that here?
Title: Re: My BASIC Questions
Post by: kotu on November 14, 2016, 03:25:11 AM
Someone else can help you, not me.
Title: Re: My BASIC Questions
Post by: kotu on November 14, 2016, 03:29:24 AM
Can someone help _xmarminq with some getkey() function equivalent and some timer function for TI-BASIC. Thanks  (-_(//));

*Edit*
@xMarminq_ check out these 2 webpages...

http://tibasicdev.wikidot.com/getkey (http://tibasicdev.wikidot.com/getkey)

http://tibasicdev.wikidot.com/timers (http://tibasicdev.wikidot.com/timers)

ps. sorry for top-posting  :'(
Title: Re: My BASIC Questions
Post by: JWinslow23 on November 14, 2016, 03:46:30 AM
@xMarminq_ , I could help. I'm not sure you're being specific enough, but it sounds like a Cookie Clicker-type thing.

You will have to be more specific, though. What project are you working on? Can you describe what it's supposed to look like? Do you have a TI-83+, TI-84+, or the TI-84+ color models? (as far as timers, there are differences between different models)
Title: Re: My BASIC Questions
Post by: xMarminq_ on November 14, 2016, 09:21:42 PM
It is a CE, (5.2 OS) and I want something around a game where you press a button as much as you can to get to certain value in an amount of time (maybe when a key pressed add symbol +, when time expires delete last +, constant decrease of +1 every second) and the If A=7 (Goal) , do this, If A≥7, Menu for restart, if A≤7, action as if goal. (IS this possible? let me know.
Title: Re: My BASIC Questions
Post by: JWinslow23 on November 14, 2016, 11:15:13 PM
Quote from: xMarminq_ on November 14, 2016, 09:21:42 PM
It is a CE, (5.2 OS) and I want something around a game where you press a button as much as you can to get to certain value in an amount of time (maybe when a key pressed add symbol +, when time expires delete last +, constant decrease of +1 every second) and the If A=7 (Goal) , do this, If A≥7, Menu for restart, if A≤7, action as if goal. (IS this possible? let me know.

Quote from: xMarminq_ on November 14, 2016, 09:21:42 PM
(IS this possible? let me know.
TI-BASIC is Turing-complete; basically, anything's possible ;) .

So, what you might be looking for here is a Repeat loop and getKey. Repeat has this syntax:
Repeat <conditional>
<code>
End

Where <conditional> is the conditional that will end the loop when it is true, and <code> is the code to repeat.
Repeat always runs unconditionally once, then at the end of the loop, it checks the conditional, and exits if it's true, and otherwise it restarts.

getKey is a number that depends on the row and column of the current key pressed (for example, Y= is 11 because it's in row 1 column 1, PRGM is 43 because it's in row 4 column 3, etc). There are only two "exceptions"; row 2 is considered to have 2ND, MODE, DEL, LEFT, UP, and RIGHT, and row 3 is considered to have ALPHA, XTON, STAT, and DOWN.

I obviously cannot write the code for you (you know your game idea better than me), but here's a rough guideline:
Repeat A>=7         // I assume that's what you want to end on. You never told me what it meant, though.
  getKey->K
  If K=<keycode>    // put keycode here
  Then
    <action for a keypress>
  End
  <other actions>
End


Still not sure exactly what you mean by your idea, but hopefully I helped!

Oh, and timer commands will be useful too, but I don't wanna teach you about them unless I know it's precisely what you need.
Title: Re: My BASIC Questions
Post by: xMarminq_ on November 17, 2016, 12:21:12 AM
I want dat :D (Timer)
ill try it when I get to that part of my project I'm making
Title: Re: My BASIC Questions
Post by: SiphonicSugar on November 17, 2016, 02:20:52 AM
This may help a little:

"Multitasking does not necessarily mean that multiple tasks are executing at exactly the same time (simultaneously). In other words, multitasking does not imply parallel execution, but it does mean that more than one task can be part-way through execution at the same time, and that more than one task is advancing over a given period of time." - Wikipedia

So, multitasking is probably going to be very hard without having multiple cores. (I'm pretty sure the z80 only has 1 core...)

Just try to make sure to optimize your code very well to get the fastest speeds. That is pretty much the only way I can think of getting the "illusion" of multitasking.
Title: Re: My BASIC Questions
Post by: p2 on November 17, 2016, 10:44:12 AM
multitasking:
you got 10 programs running
the processor can execute 1000 tasts every second
so you witch between them and execute 100 tasks of every program per second.
If one programm (/process) is set on higher priority, you do 500 of that one and only 55 for each other program in that second.
so you share the processor "time" you have among the running programs.
that's called "Task sceduler" :)
that's (suuuuper low-lever) how multitasking on computers works ;)

for a program with multiple threads, it's more or less similar.
*this is not accurate, just so you understand that way of not "really" doing stuff at the same time ;)
Title: Re: My BASIC Questions
Post by: SiphonicSugar on November 17, 2016, 09:05:19 PM
Yeah, one of the major operating system breakthroughs was when multi threaded CPUs were released. Multitasking will be amazingly hard without more than one thread.
Title: Re: My BASIC Questions
Post by: p2 on November 17, 2016, 10:04:30 PM
the best way for calc programming is still making a while loop and putting calls for all sup-programs you need in it ^^
like this:
while-loop {
check input
move player
render stuff
display all
}
and then just try to make the loop run as fast as possible :)
once you reach a nice speed it's gonna look like doing it all (almost) at the same time ^^