Thread: 508 - Member Countdown Help.. again

Page 1 of 2 12 LastLast
Results 1 to 10 of 18
  1. #1 508 - Member Countdown Help.. again 
    Registered Member
    AndyJay's Avatar
    Join Date
    Jun 2008
    Posts
    1,285
    Thanks given
    38
    Thanks received
    48
    Rep Power
    84
    Okay, I'm making a member system from scratch for my server. Everything is working apart from the days don't count down.

    I've made it record the System.currentTimeMillis() when the member registers to a text file.

    I've got a FileReader reading the currentTimeMillis which is in the text files. The data goes into player.java in public String lastTime = "";

    I need the currentTimeMillis subtracted from the read data. So it's something like this.
    if((System.currentTimeMillis - lastTime) >= 86400000){

    But it wont work because the lastTime is a string or whatever... I've been trying to make it work and it's started annoying me badly. Can somebody please help... :/
    Reply With Quote  
     

  2. #2  
    Registered Member
    AndyJay's Avatar
    Join Date
    Jun 2008
    Posts
    1,285
    Thanks given
    38
    Thanks received
    48
    Rep Power
    84
    Anybody?
    Reply With Quote  
     

  3. #3  
    Member

    Join Date
    Dec 2007
    Posts
    1,094
    Thanks given
    8
    Thanks received
    8
    Rep Power
    0
    what are you trying to say? explain a little more.

    something like...

    make lasttime an int and run a timer in process??
    Reply With Quote  
     

  4. #4  
    Registered Member
    AndyJay's Avatar
    Join Date
    Jun 2008
    Posts
    1,285
    Thanks given
    38
    Thanks received
    48
    Rep Power
    84
    @ Dennis
    I'm trying to make the string lastTime into an int so it can be subtracted from the System.currentTime... (how do I change it from a string to an int without it nackering up the filereader etc?)

    And I wasn't planning on putting it into the process. I was going to put it in login.java etc. When a user logs in (and they are a member) it checks to see if a day or more has advanced since the FileReader's time. If the time has advanced it removes the member days and then it puts the current time into the file to be checked next time, so it doesn't keep taking days each time a user logs in.
    Reply With Quote  
     

  5. #5  
    Registered Member

    Join Date
    Sep 2008
    Posts
    1,801
    Thanks given
    4
    Thanks received
    50
    Rep Power
    636
    Heres one way to convert a string to a int
    Code:
    if((System.currentTimeMillis - Integer.parseInt(lastTime))
    use that code ^
    Reply With Quote  
     

  6. #6  
    Member

    Join Date
    Dec 2007
    Posts
    1,094
    Thanks given
    8
    Thanks received
    8
    Rep Power
    0
    Quote Originally Posted by AndyJay123 View Post
    @ Dennis
    I'm trying to make the string lastTime into an int so it can be subtracted from the System.currentTime... (how do I change it from a string to an int without it nackering up the filereader etc?)

    And I wasn't planning on putting it into the process. I was going to put it in login.java etc. When a user logs in (and they are a member) it checks to see if a day or more has advanced since the FileReader's time. If the time has advanced it removes the member days and then it puts the current time into the file to be checked next time, so it doesn't keep taking days each time a user logs in.
    i still kind of don't understand, why not just set lastTime to a int instead of a string? Since it has to hold numbers anyways.
    Reply With Quote  
     

  7. #7  
    Registered Member
    AndyJay's Avatar
    Join Date
    Jun 2008
    Posts
    1,285
    Thanks given
    38
    Thanks received
    48
    Rep Power
    84
    @ Dennis
    It didn't work last time.. But I'll have another go now.

    @ Zachhh
    Thanks I think i'll try that before trying what Dennis said!

    ---------- Post added at 05:19 PM ---------- Previous post was at 04:52 PM ----------

    Okay guys it works in compiling but when I actually try(with a command), the debug gets an error.
    Here's the code I used:

    Code:
    public void RefreshMemberDay(Player p) {
    LoadMemberDay(p);
    if((System.currentTimeMillis() - Integer.parseInt(p.lastTime)) >= 86400000){
    p.frames.sendMessage(p, "Membership day test succesfull.");
    }
    }
    Here's the error:
    Code:
    java.lang.NumberFormatException: For input string: "1235066653625"
            at java.lang.NumberFormatException.forInputString(Unknown Source)
            at java.lang.Integer.parseInt(Unknown Source)
            at java.lang.Integer.parseInt(Unknown Source)
            at Bulby.players.MemberHandler.RefreshMemberDay(MemberHandler.java:67)
            at Bulby.io.packets.Commands.handlePacket(Commands.java:947)
            at Bulby.io.PacketManager.parsePacket(PacketManager.java:382)
            at Bulby.io.Packets.parseIncomingPackets(Packets.java:94)
            at Bulby.Engine.run(Engine.java:187)
            at java.lang.Thread.run(Unknown Source)
    Uhh now what?
    Reply With Quote  
     

  8. #8  
    Member

    Join Date
    Dec 2007
    Posts
    1,094
    Thanks given
    8
    Thanks received
    8
    Rep Power
    0
    lol oh wait, i see the problem (well one of them if there are any more) you are going out of bounds on int (it only goes so far) so use a double (or long) instead of parse int

    Code:
    double.parseDouble(p.lastTime)
    i don't know i'm still confused i just need to take a second and think about this.
    Reply With Quote  
     

  9. #9  
    Registered Member
    AndyJay's Avatar
    Join Date
    Jun 2008
    Posts
    1,285
    Thanks given
    38
    Thanks received
    48
    Rep Power
    84
    Quote Originally Posted by Dennis View Post
    lol oh wait, i see the problem (well one of them if there are any more) you are going out of bounds on int (it only goes so far) so use a double (or long) instead of parse int

    Code:
    double.parseDouble(p.lastTime)
    i don't know i'm still confused i just need to take a second and think about this.
    Lol I was thinking that the number was too long for the int, according to some java forum thingy anyway. I'll try the parseDouble what you said ^ and let you know.


    Yay thanks mate. Got it working after adding a capital D for Double.parse... All I need to do now is try make it check for two days, then 3 days. Then anything after 3 days can just remove 3 days member

    Sure I'll be able to do that - Thanks for everything.. Rep+
    Reply With Quote  
     

  10. #10  
    Member

    Join Date
    Dec 2007
    Posts
    1,094
    Thanks given
    8
    Thanks received
    8
    Rep Power
    0
    sorry for lowercase d, didn't mean it

    but np
    Reply With Quote  
     

Page 1 of 2 12 LastLast

Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •