Hello,I want to make an application where there were a target number and a available Claim balance.
It will be increase upto target amount even the user ofline or exit app.and when it will 5000/5000 it will automatically off.and when user claim it click on a button it be increase again upto target.
To create this application in Kodular, you’ll need to manage a few components and logic blocks. Here’s a step-by-step guide:
Components Needed:
- TinyDB: To store the claim balance persistently.
- Clock: To update the claim balance periodically.
- Button: To allow the user to claim the balance.
- Label: To display the current claim balance and the target balance.
Steps:
-
Initialize Components:
- Add a
TinyDB
component to store the claim balance. - Add a
Clock
component and set itsTimerInterval
to a suitable value (e.g., 1000 ms for 1 second). - Add a
Button
for claiming the balance. - Add a
Label
to display the claim balance and target balance.
- Add a
-
Initialize Variables:
- Create a variable for the target balance (e.g.,
targetBalance
set to 5000). - Create a variable for the current claim balance (e.g.,
claimBalance
).
- Create a variable for the target balance (e.g.,
-
Screen Initialization:
- On the screen initialization event, load the claim balance from
TinyDB
. - If no value is found in
TinyDB
, initializeclaimBalance
to 0.
- On the screen initialization event, load the claim balance from
-
Clock Timer Event:
- In the Clock’s
Timer
event, increment the claim balance by a certain amount (e.g., 1). - Check if the claim balance has reached the target balance.
- If it has, stop the clock and update the label to indicate the balance is ready to claim.
- In the Clock’s
-
Claim Button Click Event:
- When the user clicks the claim button, reset the claim balance to 0.
- Start the clock again to continue incrementing the balance.
- Save the new claim balance to
TinyDB
.
Example Blocks:
Screen Initialization
when Screen1.Initialize
set global claimBalance to call TinyDB1.GetValue tag "claimBalance" valueIfTagNotThere 0
call Clock1.TimerEnabled to true
call Label1.Text to join "Balance: " global claimBalance " / " global targetBalance
Clock Timer Event
when Clock1.Timer
if global claimBalance < global targetBalance then
set global claimBalance to global claimBalance + 1
call TinyDB1.StoreValue tag "claimBalance" value global claimBalance
call Label1.Text to join "Balance: " global claimBalance " / " global targetBalance
else
call Clock1.TimerEnabled to false
call Label1.Text to "Balance: 5000 / 5000 (Ready to claim)"
Claim Button Click Event
when Button1.Click
set global claimBalance to 0
call TinyDB1.StoreValue tag "claimBalance" value 0
call Clock1.TimerEnabled to true
call Label1.Text to join "Balance: " global claimBalance " / " global targetBalance
Summary:
This setup ensures that the claim balance increments up to the target amount even if the user is offline or exits the app. Once the balance reaches the target, it stops incrementing until the user claims it. After claiming, the balance starts incrementing again.
Feel free to modify the intervals and increment values according to your application’s requirements.
It’s chatgpt answer
It does not work when the app is exited or offline.Here is my Blocks…
Can anyone help me Please
are you trying to build hamster combact?
No,but I need same Process
They use server based techniques for adding coin
I need counting even offline.
Can you send me the block using the extension you reffed.
i will build a similiar project please wait
Try using start time and current calculate
If you need I will sent an advanced version soon
please give me a aia filw