I am building an app that keeps track of various stats of players on a court. One of the stats is total time on the court during a game. After reviewing various help posts and instructional videos, I have come close to what I am trying to do. "Court Start" button will start my timer, "Out" button will stop it.
I have attached a screenshot of my block code of what is working (but resetting each time). I understand why the timer resets to zero, and I did find a video that shows how to essentially "pause" the timer, but that video showed a method that was ridiculously long and seemed very inefficiant (potentially using a lot of memory too). I also have a "Out Minus" button, this is incase the Out button is pressed by mistake, in which case when "-" is pressed, it needs to restart the timer where it left off. I figure a list of somekind will accomplish this fine, except I cant seem to be able to save the individual times to a list (except ones that show up as some string of numbers that does not look like time at all).
Set the TimerInterval to a ridiculously large number.
Increment a variable (with a default value of one) by one when the Clock.Timer event is fired, and set the time to that variable multiplied by the TimerInterval.
You say you are trying to keep on-court times of players, but your code does not mention which player's time stats are being updated?
Your app needs several tables, which can be kept in TinyDB NameSpaces to save on re-typing during a match:
PlayerTeamDB (Namespace PlayerTeamDB)
tag: player name of a player in the league
value: player team
That should be built by you between games.
OnCourtMSDB: (NameSpace OnCourtMSDB)
tag: player name of one of the players currently on court, copied from PlayerTeamDB
value: Clock1.SystemTime of milliseconds from 1970 of when the player entered the court, otherwise 0 if not on court
That should start out empty before the first player enters the court for the current game.
value: total time in ms spent by that player on court (0 if not found)
This can start out empty when the league is set up and be built up automatically as players leave the court
I recommend saving the data in ms, because that format makes for easy math and can be easily converted to display format using the Clock blocks.
You will need a few List Pickers to make it easy to send in and take out players:
lpkSendInAPlayer
Elements to be (players in league taglist) minus (players on court)
when selected, add player and Clock1.SystemTime to OnCourtMSDB
lpkRemoveAPlayer
Elements to be taglist of OnCourtMSDB
when selected,
retrieve CumulativeOncourtMSDBms for that player,
add to it (Clock1.SystemTime - OnCourtMSDB value for that player)
save updated CumulativeOncourtMSDBms for that player
remove that player from OnCourtMSDB
lpkCumulatovePlayerStats
Elements: Built from CumulativeOncourtMSDB, in form
name: HH:MM:SS
The code I posted is only the code relevant to the timer. There is far more code that relates to other stats (Throws, hits, catches, sprinting, etc). Though, currently I am just building the setup for a single player and was planning on copying it for the other players.
In the long-run I want 3 players displayed at a time, these three players are chosen by the head coach on another tablet. The HC tablet will choose 6 players to go onto the court, those 6 will be split into 3s and sent to two other tablets (assistant coaches) who will then record the data as the game goes on. These stats are then projected to the HC tablet so they can make better informed decisions on the fly. If need be, like if one of the two assistant coaches cannot make it to the game, I would like the HC to be able to send all 6 players to 1 tablet.
I hope this information helps to better inform you as to my end goals, perhaps it may change the advise you are giving here.
I greatly appreciate the help, I am new to the app inventor so am unsure of it's full potential. Perhaps my vision is too complicated for the App Inventor and should switch over to Java or other coding.
Depending on the situation, they may or may not have wifi access. I was thinking either have them connected via bluetooth, or possibly use a laptop as a sort of hub.