The forum of the forums

Would you like to react to this message? Create an account in a few clicks or log in to continue.
The forum of the forums
2 posters

    Check if a user has pressed a button function

    TheCrow
    TheCrow
    Manager
    Manager


    Male Posts : 6916
    Reputation : 795
    Language : Greek, English

    Solved Check if a user has pressed a button function

    Post by TheCrow 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!



    Check if a user has pressed a button function Thecro10
     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!
    masesm
    masesm
    Forumember


    Male Posts : 75
    Reputation : 7
    Language : Java, C++, C#, Python, JavaScript, PHP, MySQL, AWS
    Location : United States

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

    Post by masesm 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!
    TheCrow
    TheCrow
    Manager
    Manager


    Male Posts : 6916
    Reputation : 795
    Language : Greek, English

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

    Post by TheCrow 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!



    Check if a user has pressed a button function Thecro10
     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!
    masesm
    masesm
    Forumember


    Male Posts : 75
    Reputation : 7
    Language : Java, C++, C#, Python, JavaScript, PHP, MySQL, AWS
    Location : United States

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

    Post by masesm 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.
    TheCrow
    TheCrow
    Manager
    Manager


    Male Posts : 6916
    Reputation : 795
    Language : Greek, English

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

    Post by TheCrow 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



    Check if a user has pressed a button function Thecro10
     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!
    avatar
    Guest
    Guest


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

    Post by Guest June 3rd 2017, 9:44 am

    TheCrow
    TheCrow
    Manager
    Manager


    Male Posts : 6916
    Reputation : 795
    Language : Greek, English

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

    Post by TheCrow 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



    Check if a user has pressed a button function Thecro10
     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!

      Current date/time is November 14th 2024, 9:31 pm