+ Reply to Thread
Results 1 to 4 of 4

Thread: Run code only ONCE when first user enters the room

  1. #1
    Junior Member
    Join Date
    May 2006
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Run code only ONCE when first user enters the room

    Hi, for my game I need some code to create a room variable when only the FIRST user enters the room, and for it not to be run when the other users enter (they will simply retrieve the variable set by the first user)... it seems that es.isGameMaster was for this specific purpose, but I cant figure out how to use it and am afraid it's deprecated since the documentation states it's not used much anymore. What is the alternative?

    (I should mention that I have used this tactic with some success:
    Code:
    if (es.getUser().Name.value == userlist[0].Name.value){
                 ...(code to run once)
             } else {
                 ...(code for other users to run)
             }
    Unfortunately, it works only like 50% fo the time.)

  2. #2
    Electrotank jobem's Avatar
    Join Date
    Apr 2004
    Posts
    996
    Thanks
    0
    Thanked 24 Times in 17 Posts
    Hi rudeaminute,

    A room variable has an optional 'locked' property. If set to true then that room variable cannot be overwritten, but I can be deleted.

    Based on the rules that you mentioned above, you should be able to have everyone try to set the room variable when they enter the room with locked=true. The first one received by ElectroServer will work. All clients will receive the appropriate variable name/value as a response.

    This is directly from the documentation:
    Code:
    var ob:Object = new Object();
    ob.name = "secretDoorUnlocked";
    ob.data = "true";//this is a string because all room variables are strings
    ob.locked = true;
    ob.persistent = true;
    es.createRoomVariable(ob);
    ------
    Jobe Makar
    @jobemakar
    http://www.electrotank.com

    YouTube ElectroServer video tutorials
    http://www.youtube.com/user/ElectrotankInc

  3. #3
    Junior Member
    Join Date
    May 2006
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Sorry, I forgot to mention that once the room variable has been set I need to modify it continuously (I'm making a countdown). If I lock it, I can no longer modify it. If I don't lock it, and each user sets it on their own, the countdown no longer decrements by 1 but by the number of users in the room.

    Is there any way other than locking a room variable to get the first user and only the first user to set the variable and then run code on that variable, while the other users merely retrieve the results of the operations?

  4. #4
    Electrotank jobem's Avatar
    Join Date
    Apr 2004
    Posts
    996
    Thanks
    0
    Thanked 24 Times in 17 Posts
    Hi Rudeaminute,

    Sounds like you need a plugin. If you are going to do a countdown, then you need the server to handle counting down. I'd recommend looking into that a bit. They are pretty easy to use and can do quite a bit.
    ------
    Jobe Makar
    @jobemakar
    http://www.electrotank.com

    YouTube ElectroServer video tutorials
    http://www.youtube.com/user/ElectrotankInc

+ Reply to Thread

Tags for this Thread

Posting Permissions

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