timer help

From now on, we will use this info box to inform you about noteable updates on our Trello-Roadmap!

Trello update: We've recently implemented grass and now finalized the occlusion renderer to prevent grass from passing through objects. In addition to that, snowfall now also affects meadows
  • A description of what you are attempting to achieve and a snippet of the code you are using would make helping much easier.

    There is no formulated code yet. I am experimenting with the timer and hit a brick wall in the format errors. I want to achieve a timer that I can start inside a routine and get it to run once but it seems to check if the timer is running I need an ID not a name. So it is the use of the isActive parameter to check if the timer is running before I let another routine enter otherwise I am telling the player to wait and come back later. The messaging I can handle it is the timer check and making sure it is the correct timer if I have more than one running.

  • Here is a basic timer example, hope it helps:


  • Ok Mino


    What if I want to initialize the timer but not run code then start it down in the other code. The example you have triggers when the timer is over. I dont want to do anything when it is over but I want to prevent the code from running if the timer is running. So the check for if it is running seems to be correct but the example you gave and the one in the API are both .. execute when the timer triggers. When I start it at the end of my routine I get an error. The timer has to run outside of the routine until it finishes. It is a delay of the routine between the ability to trigger by the player.


    So I put a null in the timer and that seems to compile but it soft warns me that I am hiding a variable. This is no matter where i put the timer initialization with the @event or onEnable

  • Progress got rid of that error.. the routine runs and the timer is running that sets the flag the send a message to wait.. I guess I need to find out if the timer ever stops or is reinitialized every event. Right the timer starts no matter what object I interact with and not just the specialized one I want.


    I guess I will have to capture that it is the correct type of object prior.. ^^


    That did it..got it running. but I failed to start the timer inside the execution loop so it always ran and no longer stopped with a message.


    I am adjusting now but I have a question. If I define and start a timer in an Event does the timer keep running if I cancel the event? It is initialized as public static. I am hoping it keeps running until it runs out of time . I did not kill it. Then if the event is reentered the timer has to have finished before it will execute again. A


    --- Apparently so.. the timer stops.


    I guess I need to find a way to make it run independently of the event method. If I initialize it at the start if always is running and is always caught to stop the routine.. but if I start it inside the routine and cancel the event the timer seems to stop and the next time it runs as if no timer.

  • Did you try the documentation at https://javadoc.rising-world.net/?

    Yes, thank you, I did it is from which the concept of what I can possibly do comes. However, the example was not very helpful in defining how the parameters are used. For you seasoned programmers I suppose the structure of how to address a statement of isActive() is second nature. While I understand flow and logical progression of loops and if statements, I am not as versed in the Java requirements for what isActive looking for, how it knows where to look and where the, what I call adjectives, tell it what it is it is supposed to act with or against.


    I have the statements working it is the use of an internal or external timer that tells the loops that they can proceed. The timer in the loop is never active. The timer out of the loop is the answer but was not being triggered one the routine runs. The examples have the timer executing the commands but I am not wanting to execute but prevent from executing while the timer loop runs.


    Thanks though.. I have it working now. The Timer was needed to be in the public static statement not in the event. Starting in the execution statement works but if you define it in the execution it stops when the event if cancelled. That aspect was not understood by me, as I expected it to run independent of the statement by the system once launched.


    Thanks Minos for the static lesson there. ;)


    OOps talked to soon.. works first time but not second time.

  • Thanks though.. I have it working now. The Timer was needed to be in the public static statement not in the event. Starting in the execution statement works but if you define it in the execution it stops when the event if cancelled. That aspect was not understood by me, as I expected it to run independent of the statement by the system once launched.

    Timers are indeed independent and cancelling the event shouldn't affect them. Probably something else is going on in there :/ If I could see the source code maybe I could help more with that :)

  • Timers are indeed independent and cancelling the event shouldn't affect them. Probably something else is going on in there :/ If I could see the source code maybe I could help more with that :)

    ok I know I know well it works the first time through.. it executed the not active else statement then it catches the timer running everytime for the length of the timer. However once the timer has stopped timed out it is not being restarted by the start in the execution routine so then it just bounces to this not active routine. This is execution delay routine. I need to start a new timer each time so the speak but did not want to create a whole new one I want it to run .. then when it is over I need to restart it as if the routine was seen for the first time .


    I might start a conversation up with you rather than adding it here. But here is the question. If I have a if (mytimer.isActive()){ the routine will execute of the timer is running (true). It will skip the routine from runnning (false). How do you detect the false statement and run as the opposite and in this opposite routine start the timer again to prevent it from running for the delay?

  • The normal if else does not seem to do what I want it to do with the timer being in static and the start at the end of the else. I know start will do nothing if the timer is already running but if it is stopped I need it to start the timer again.. If the timer is set to run just once mytimer = new Timer(120f, 0f, 0,null); and it is in static will it not run again from a start in an executed routine? Do I have to declare a new timer and start it?


    I thought kill would return the assets and allow me to restart but that is not true either. That just throws errors.


    There is no restart function in the API as far as I can see.

  • Finally got to work correctly with if isActive. say you have to wait. else if execute then initialize timer after execution.. else cancel event.


    Somehow I am not catching a null placement .. and I get a bunch of errors ..


    Do signs have a definition if they are placed empty .. they must have one if you are editing them.


    What I get if I pick a blank sign.. A sign with any writing works fine no errors.


    PLUGIN EXCEPTION (angriffspawnnpcsign1.0, 0.1.2, angriff) ---->
    java.lang.NullPointerException
    at angriffspawnnpcsign.Angriffspawnnpcsign.onObjectInteraction(Angriffspawnnpcsign.java:55)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at pluginapi.PluginEventHandler.triggerEvent(SourceFile:206)
    at G.c.a(SourceFile:2943)
    at G.c.messageReceived(SourceFile:189)
    at de.jiw.network.server.core.ServerTcpChannel.onMessageReceived(ServerTcpChannel.java:97)
    at de.jiw.network.server.core.AbstractServerChannel.dispatchTCP(AbstractServerChannel.java:62)
    at de.jiw.network.server.session.TcpSessionHandler.channelRead0(TcpSessionHandler.java:79)
    at de.jiw.network.server.session.TcpSessionHandler.channelRead0(TcpSessionHandler.java:15)
    at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:105)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340)
    at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:310)
    at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:284)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340)
    at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:310)
    at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:284)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362)
    at io.netty.channel.AbstractChannelHandlerContext.access$600(AbstractChannelHandlerContext.java:38)
    at io.netty.channel.AbstractChannelHandlerContext$7.run(AbstractChannelHandlerContext.java:353)
    at io.netty.util.concurrent.DefaultEventExecutor.run(DefaultEventExecutor.java:66)
    at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:858)
    at io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:138)
    at java.lang.Thread.run(Unknown Source)

  • glad to hear you got it to work :)


    signs do have a definition no matter if they have text on them or not, the definition is what holds all the information about signs, e.g. they object ID, their variations, etc.


    can I see the snippet of the code causing the null pointer exception?

    so can you tell what snipet other than the entire code makes the error from that mess?

Participate now!

Don’t have an account yet? Create a new account now and be part of our community!