Check if a user has pressed a button function
2 posters
Page 1 of 1
Check if a user has pressed a button function
Hello all,
So, i am creating a game where i want all users to be able and click a button once per day. Once the button is clicked, they will get a result out of this and then they can press it again after 24 hours from the last time they pressed it.
So my question is: How is it possible to prevent a user from pressing the button again before the 24 hours have passed for him?
For example: I press at 3AM.
User 1 presses at 3:15AM.
I willl be able to press the button again at 3am the next day and user 1 at 3:15am the next day. Now if the next day i press it at 6am then i'll have to wait the next day till 6am.
I have an idea on how to do this but i believe i need to do cache control for the 24 hour span time and i don't know how to do this.
Big Plan:
A green button. Once pressed, turns gray and not able to press it, after 24 hours turns green and can be pressed to work the game i want.
( So easy to write down in words, so difficult to code, at least for me.. )
Any help would be appreciated. Thanks!
So, i am creating a game where i want all users to be able and click a button once per day. Once the button is clicked, they will get a result out of this and then they can press it again after 24 hours from the last time they pressed it.
So my question is: How is it possible to prevent a user from pressing the button again before the 24 hours have passed for him?
For example: I press at 3AM.
User 1 presses at 3:15AM.
I willl be able to press the button again at 3am the next day and user 1 at 3:15am the next day. Now if the next day i press it at 6am then i'll have to wait the next day till 6am.
I have an idea on how to do this but i believe i need to do cache control for the 24 hour span time and i don't know how to do this.
Big Plan:
A green button. Once pressed, turns gray and not able to press it, after 24 hours turns green and can be pressed to work the game i want.
( So easy to write down in words, so difficult to code, at least for me.. )
Any help would be appreciated. Thanks!
Forum of the Forums Forumotion Rules | Tips & Tricks | FAQ | Did you forget your password? |
*** The Support Forum will never ask you for your email or password, so please do not post them anywhere! ***
No support via PM!
Re: Check if a user has pressed a button function
Hey Luffy, this is a great idea for a programming practice!
I will give you hints on how to achieve this. First you need to ask, how and where am I storing this info? Is it on a file? Where is that file saved? How will I be able to access this file and RETRIEVE the data I need from it. What programming language or library is being used? One thing that is vague about what you want is the button appearing grey to everyone or just the person that pressed it. If it is separate for everyone, it might be a tiny bit more advanced. The next thing you want is the time. You can store time independently on your own file, or you can retrieve time from website. Will you show each user the time at their time zone or just GMT? Use something like Python to experiment with the computation and logic, and then transfer that to (hint) javascript or PHP. Good luck!
I will give you hints on how to achieve this. First you need to ask, how and where am I storing this info? Is it on a file? Where is that file saved? How will I be able to access this file and RETRIEVE the data I need from it. What programming language or library is being used? One thing that is vague about what you want is the button appearing grey to everyone or just the person that pressed it. If it is separate for everyone, it might be a tiny bit more advanced. The next thing you want is the time. You can store time independently on your own file, or you can retrieve time from website. Will you show each user the time at their time zone or just GMT? Use something like Python to experiment with the computation and logic, and then transfer that to (hint) javascript or PHP. Good luck!
Re: Check if a user has pressed a button function
masesm wrote:Hey Luffy, this is a great idea for a programming practice!
I will give you hints on how to achieve this. First you need to ask, how and where am I storing this info? Is it on a file? Where is that file saved? How will I be able to access this file and RETRIEVE the data I need from it. What programming language or library is being used? One thing that is vague about what you want is the button appearing grey to everyone or just the person that pressed it. If it is separate for everyone, it might be a tiny bit more advanced. The next thing you want is the time. You can store time independently on your own file, or you can retrieve time from website. Will you show each user the time at their time zone or just GMT? Use something like Python to experiment with the computation and logic, and then transfer that to (hint) javascript or PHP. Good luck!
Thank you so much @masesm,
This button will be a generator of 20 messages. Once a member has pressed this button, the button will turn gray, only for the member who pressed it and show the time he needs to wait in order to press the button again. Once the button is pressed, an alert will popup with a random message for the user. Then users must take an image out of it and send it to me via pm. That way i'll avoid editing messages etc and i will have a button that will generate those 20 messages and members being able to press it just once. I am not familiar with Python nor PHP. I am trying to achieve this using javascript but the thing is i don't know how to make the button grey for 24 hours and show a 24 hour counter for the user and when (s)he refreshes the time to continue to run..
Thanks!
Forum of the Forums Forumotion Rules | Tips & Tricks | FAQ | Did you forget your password? |
*** The Support Forum will never ask you for your email or password, so please do not post them anywhere! ***
No support via PM!
Re: Check if a user has pressed a button function
Remember any counter or clock is just a number. With that said, the first step is storing the user's time. You can even use Forumotion's profile fields to accomplish this. Every time that user hits that green button, update the user profile field with day, month, year, hour, minutes seconds. You need to keep this time consistent with a time zone, say GMT. Next, every time the user access the page which checks for the time, and how much time they have left, use an official website like time.gov (or any other reliable website that updates every second, this way you don't have to keep and update server time) to retrieve the current time. Subtract this time from the user's current time and this is how much time has passed. Remember to: 1) convert everything to milliseconds when subtracting time, I learned that the hard way. 2) You can actually do everything I just mentioned in Javascript. Let me know if you need further help.
Re: Check if a user has pressed a button function
Hello again @masesm,
The thing is i am new to Javascript and i'm still trying to learn some things. Now what you told me make absolutely sense but the thing is i don't really know how to do all that.. I'm just familiar with the basic staff and maybe a bit more but not to a point where i can store stuff and use them for other reasons..
The thing is i am new to Javascript and i'm still trying to learn some things. Now what you told me make absolutely sense but the thing is i don't really know how to do all that.. I'm just familiar with the basic staff and maybe a bit more but not to a point where i can store stuff and use them for other reasons..
Forum of the Forums Forumotion Rules | Tips & Tricks | FAQ | Did you forget your password? |
*** The Support Forum will never ask you for your email or password, so please do not post them anywhere! ***
No support via PM!
Re: Check if a user has pressed a button function
Hello,
This should help you:
https://help.forumotion.com/t141857-datastore-localstorage-expiration-made-easy
This should help you:
https://help.forumotion.com/t141857-datastore-localstorage-expiration-made-easy
Guest- Guest
Re: Check if a user has pressed a button function
Thank you guys. Your replies helped me a lot! Regards.
Problem solved & topic archived.
|
Forum of the Forums Forumotion Rules | Tips & Tricks | FAQ | Did you forget your password? |
*** The Support Forum will never ask you for your email or password, so please do not post them anywhere! ***
No support via PM!
Similar topics
» Check user’s messages before publication
» user rank button
» Auto PM to specific user through a button
» Help! When pressed open bellow word!
» Is there an Admin button to delete all messages from a user?
» user rank button
» Auto PM to specific user through a button
» Help! When pressed open bellow word!
» Is there an Admin button to delete all messages from a user?
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum