The forum of the forums
Welcome to the Official Support Forum of Forumotion!

To take full advantage of everything offered by our forum, please log in if you are already a member, or join our community if you've not yet.



Create a free forum like this one.

Check if a user has pressed a button function

View previous topic View next topic Go down

Solved Check if a user has pressed a button function

Post by Luffy on May 30th 2017, 3:35 pm

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.. Sad )

Any help would be appreciated. Thanks!





avatar
Luffy
Manager
Manager

Male Posts : 4623
Reputation : 466
Language : Greek, English
Location : Greece

http://helpgr.forumgreek.com/forum

Back to top Go down

Solved Re: Check if a user has pressed a button function

Post by masesm on May 31st 2017, 7:44 am

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!
avatar
masesm
Forumember

Male Posts : 71
Reputation : 6
Language : English, Java, JavaScript, HTML, CSS.
Location : United States

http://sicktier.forumotion.com/

Back to top Go down

Solved Re: Check if a user has pressed a button function

Post by Luffy on May 31st 2017, 11:30 am

@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.. Confused

Thanks!





avatar
Luffy
Manager
Manager

Male Posts : 4623
Reputation : 466
Language : Greek, English
Location : Greece

http://helpgr.forumgreek.com/forum

Back to top Go down

Solved Re: Check if a user has pressed a button function

Post by masesm on June 2nd 2017, 2:47 am

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.
avatar
masesm
Forumember

Male Posts : 71
Reputation : 6
Language : English, Java, JavaScript, HTML, CSS.
Location : United States

http://sicktier.forumotion.com/

Back to top Go down

Solved Re: Check if a user has pressed a button function

Post by Luffy on June 2nd 2017, 11:08 pm

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.. Sad





avatar
Luffy
Manager
Manager

Male Posts : 4623
Reputation : 466
Language : Greek, English
Location : Greece

http://helpgr.forumgreek.com/forum

Back to top Go down

Solved Re: Check if a user has pressed a button function

Post by Wolfuryo on June 3rd 2017, 9:44 am

avatar
Wolfuryo
Forumember

Posts : 346
Reputation : 92
Language : Romanian and English

http://board.realmsn.com

Back to top Go down

Solved Re: Check if a user has pressed a button function

Post by Luffy on June 3rd 2017, 2:45 pm

Thank you guys. Your replies helped me a lot! Regards.

Problem solved & topic archived.
Please read our forum rules: ESF General Rules





avatar
Luffy
Manager
Manager

Male Posts : 4623
Reputation : 466
Language : Greek, English
Location : Greece

http://helpgr.forumgreek.com/forum

Back to top Go down

View previous topic View next topic Back to top


 
Permissions in this forum:
You cannot reply to topics in this forum