Comments on "Script functions documentation"

Discussion in 'Server and Client Scripting' started by Mystra, Sep 8, 2010.

Thread Status:
Not open for further replies.
  1. Mystra

    Mystra Active Member

    Joined:
    Jul 12, 2010
    Messages:
    1,389
    Likes Received:
    4
    Here you can comment on Script functions documentation.

    Errors, absent functions, suggestions, pointing out that something is illogical, etc.

    You can try a (scripting) feature request too. If we'll see it interesting and possible to do I (or someone else) will try to implement it. Please write why do you think it is needed and mark feature request with a "feature request" in the comment title so they are easier to find.
     
    Last edited by a moderator: Sep 17, 2010
  2. Lutra

    Lutra All Gen Battler/Scripter

    Joined:
    Apr 25, 2010
    Messages:
    509
    Likes Received:
    188
    PO Trainer Name:
    Lutra
    All of these changes need to be added also.
     
  3. Mystra

    Mystra Active Member

    Joined:
    Jul 12, 2010
    Messages:
    1,389
    Likes Received:
    4
    I'm adding some functions from changelogs right now. I'll look there after that, thank you.

    EDIT: done.
     
    Last edited: Sep 8, 2010
  4. Elyvilon

    Elyvilon New Member

    Joined:
    Jul 1, 2010
    Messages:
    18
    Likes Received:
    0
    Small error on the changeScript description:
    The function should be getFileContent, not readFileContent.
     
  5. Lutra

    Lutra All Gen Battler/Scripter

    Joined:
    Apr 25, 2010
    Messages:
    509
    Likes Received:
    188
    PO Trainer Name:
    Lutra
  6. Mystra

    Mystra Active Member

    Joined:
    Jul 12, 2010
    Messages:
    1,389
    Likes Received:
    4
    Elyvilon: done.

    Lutra: I think it can be the added to the same function with second optional parameter. If anyone knows how PO is dispatching events for scripts I'll be glad to learn it :} Can I just call ScriptEngine::serverStartUp() at the end of successful ScriptEngine::changeScript() run?
     
  7. coyotte508

    coyotte508 Well-Known Member Administrator Server Owner Administrator Server Owner

    Joined:
    Apr 21, 2010
    Messages:
    6,363
    Likes Received:
    168
    @Mystra: yes you can
     
  8. Mystra

    Mystra Active Member

    Joined:
    Jul 12, 2010
    Messages:
    1,389
    Likes Received:
    4
    @coyotte508: thank you (^. ^)

    @Lutra: Status: in progress.
     
  9. Lutra

    Lutra All Gen Battler/Scripter

    Joined:
    Apr 25, 2010
    Messages:
    509
    Likes Received:
    188
    PO Trainer Name:
    Lutra
    Thanks, that second optional parameter will be great. :)

    Is there any chance a ping check scripting function can be done? Like sys.ping(playerid). It was on Netbattle and seems quite useful.
     
  10. Mystra

    Mystra Active Member

    Joined:
    Jul 12, 2010
    Messages:
    1,389
    Likes Received:
    4
    Not sure, I'll ask Coyotte (^ ^)
     
  11. Mystra

    Mystra Active Member

    Joined:
    Jul 12, 2010
    Messages:
    1,389
    Likes Received:
    4
    So, it will not be implemented until at least gen 5. I don't want to touch network protocol either (^ ^)
     
  12. Lutra

    Lutra All Gen Battler/Scripter

    Joined:
    Apr 25, 2010
    Messages:
    509
    Likes Received:
    188
    PO Trainer Name:
    Lutra
    Say I had a timer that shuts the server down. Is there a way to stop that timer (and the shutting down) without having to check every second whether it should be running or not?
     
  13. Mystra

    Mystra Active Member

    Joined:
    Jul 12, 2010
    Messages:
    1,389
    Likes Received:
    4
    callLater() does not return anything unlike setTimeout() in browser's javascript. Therefore you can't actually stop a timer since there is no way to differentiate between timers. There is no clearTimeout() either.

    On the other hand timer are fired only once in PO. So, to make it repeatable you need it to call callLater() again yourself. If you don't want it to repeat — don't call it again. You can call PO to shutdown or not call it at all. Should work.

    Describe what you want to do, and I'll see what can be done.
     
  14. Lutra

    Lutra All Gen Battler/Scripter

    Joined:
    Apr 25, 2010
    Messages:
    509
    Likes Received:
    188
    PO Trainer Name:
    Lutra
    I just want to know the most efficient way of commanding a shutdown in so many seconds/minutes/hours and being able to cancel that. So would that be a case of just checking one second before it shuts down? Like set the cancelling variable - but only check if that variable is set right before it shuts down. I guess if I wanted a shutdown warning timer, it would still have to check for that variable every time it ran though.
     
  15. coyotte508

    coyotte508 Well-Known Member Administrator Server Owner Administrator Server Owner

    Joined:
    Apr 21, 2010
    Messages:
    6,363
    Likes Received:
    168
    Maybe the stepEvent script, that I posted in another topic, would be helpful? It works like Netbattle's Event Timer.
     
  16. Mystra

    Mystra Active Member

    Joined:
    Jul 12, 2010
    Messages:
    1,389
    Likes Received:
    4
    1. Either call itself with callLater() every second (or whatever arbitrary number) and check whether you need to shutdown or not.

    2. ZOMG way

    You need some global variable (or any other way) to store enabled/disabled state.

    Then implement something like runShutdownAfter(seconds) and clearShutdown().

    runShutdownAfter() will set enabled/disabled to true and will call callLater() with a check for it inside. i.e. code inside callLater() will call shutdown only if that flag is true. clearShutdown() will just set flag to false.

    This will not actually remove timer itself (so… don't call runShutdownAfter() million times in a row) until it's time will come to run. Then it will check current value of a flag before being destroyed.

    You'll need separate variables if you want to call runShutdownAfter() more than once for the time of a timer's life cycle. Either array/hash with unique index or the same with data being stored somewhere else.
     
  17. Lutra

    Lutra All Gen Battler/Scripter

    Joined:
    Apr 25, 2010
    Messages:
    509
    Likes Received:
    188
    PO Trainer Name:
    Lutra
    wow, that ZOMG way is a really simple solution. Thanks. :)
     
  18. Lutra

    Lutra All Gen Battler/Scripter

    Joined:
    Apr 25, 2010
    Messages:
    509
    Likes Received:
    188
    PO Trainer Name:
    Lutra
    An event for when a player's authority is changed in Options > Players would be good. Would mean you could reliably (server may crash before arbitrary-timed timer/serverShutDown) save auth to a reg val and then change that regval when the auth is changed in that window.

    It'd also save a bit of script if names in the db were saved in the correct mixture of upper case and lower case.

    Also, it'd help if the information in the whole db could be completely be reconstructed from reg vals reliably (like in the case of overwriting your whole Server folder for the update). Maybe there's other things in the way other than that lack of auth changing event (sorry, I haven't really looked deeply enough)?

    Finally, I don't like the fact that channel join/leave just replaced the server log in/log out message. Sometimes when they leave the main channel, they could still be in another channel on the server. I'd personally prefer if all the play event messages were scripted. The only disadvantage at the moment (other than the fact that sendall messages can't be blocked and thus you need a sendmessage loop) in doing that is that you won't be able to enable/disable by a menu. Would it be possible in the future for scripting to be able to create menus on the client? Are there problems other than like overcrowding the GUI?

    P.S. (Not entirely scripting related) I also noticed there's quite a few limitations on how you can display the tiers. Like if you set every tier with its display order, it doesn't always want to display in that order and it alternates between some other order when you click apply. Also, I was doing categories within categories and it displayed fine in the server - but in some instances, it was thrown out of a parent category as far as the client was concerned. Is this being fixed to be more flexible or are there rules we have to follow?
     
  19. Crystal Moogle

    Crystal Moogle Ayaya~ Administrator Administrator

    Joined:
    Jul 19, 2010
    Messages:
    3,205
    Likes Received:
    531
    PO Trainer Name:
    Hanako
    Feature request

    Hi, I was wondering if it was at all possible to make a command that checks the type of a pokémon? It would just help with the monotype cup we run. If it's not that's fine, we'll just do what we've been doing the past 2 months :3
     
  20. Mystra

    Mystra Active Member

    Joined:
    Jul 12, 2010
    Messages:
    1,389
    Likes Received:
    4
    I didn't quite understood why do you need it but I'll look whether it is possible. It probably is.

    Could you describe what's current behavior and why it is a problem?

    This too.

    It can be done as there are PokemonInfo::Type1() and PokemonInfo::Type2() static functions in PO code. Also they need to know which generation it is to do it. I'll try to do it after Coyotte accepts my new delayedCall() function.
     
  21. Lutra

    Lutra All Gen Battler/Scripter

    Joined:
    Apr 25, 2010
    Messages:
    509
    Likes Received:
    188
    PO Trainer Name:
    Lutra
    I need the auth change event so I can trigger code from it. Like update the auth list, update the reg val with auth saved on it, and send a message through the server that someone has been promoted/demoted.

    The db currently stores all names in lower case. When you are viewing an auth list, you ideally want to see the right mix of upper case and lower case which they last used in their name on the server.

    For the db info reconstruction, just all the necessary triggers and functions you need to add, remove, change (if viable) and obtain the data in each field of the player db. Assuming the id for it is the player's name, the auth of that player name, whether that name is banned, registered (an add problem if there's no access to encrypted passwords), their IP and last appearance. coyotte did quite a bit of it but I still think there's a few gaps.
     
  22. Mystra

    Mystra Active Member

    Joined:
    Jul 12, 2010
    Messages:
    1,389
    Likes Received:
    4
    There are auth() and ip() functions. I'll see what I can do.

    EDIT: There are PlayerBan and PlayerKick events btw.
     
  23. Lutra

    Lutra All Gen Battler/Scripter

    Joined:
    Apr 25, 2010
    Messages:
    509
    Likes Received:
    188
    PO Trainer Name:
    Lutra
    There's clear pass and change auth too. As well as all the things that have db in front. Wouldn't it make more sense to have categories : tier db functions, player db functions and pokemon db functions in the documentation? That's how I think of it.
     
  24. Mystra

    Mystra Active Member

    Joined:
    Jul 12, 2010
    Messages:
    1,389
    Likes Received:
    4
    It is possible, but it makes more categories which tend to be small. Which is not helping either.

    EDIT: clear pass and change auth? I see a function to change them, but no events.
     
  25. Lutra

    Lutra All Gen Battler/Scripter

    Joined:
    Apr 25, 2010
    Messages:
    509
    Likes Received:
    188
    PO Trainer Name:
    Lutra
    Yeah, a clear pass (on the player db window) event could also be useful. You could sendall a message into the server saying someone's password has been cleared. Also an unban one.
     
  26. Mystra

    Mystra Active Member

    Joined:
    Jul 12, 2010
    Messages:
    1,389
    Likes Received:
    4
    @Crystal Moogle: I've just finished pokeType1() and pokeType2() functions. See documentation thread for details (2.7).
     
    Last edited: Sep 24, 2010
  27. NeO

    NeO BR Scripter

    Joined:
    May 26, 2010
    Messages:
    50
    Likes Received:
    0
    Mystra, can you make functions for Bold, Italic, Color... etc?

    Example: sys.sendAll("*** This message is blue").Color("Blue").Bold();

    I think it would be really cool. ;D
     
  28. Crystal Moogle

    Crystal Moogle Ayaya~ Administrator Administrator

    Joined:
    Jul 19, 2010
    Messages:
    3,205
    Likes Received:
    531
    PO Trainer Name:
    Hanako
    Thanks!
     
  29. coyotte508

    coyotte508 Well-Known Member Administrator Server Owner Administrator Server Owner

    Joined:
    Apr 21, 2010
    Messages:
    6,363
    Likes Received:
    168
    It could be done adding a new command allowing to send html.

    Something could be done about the log out message. But otherwise, a huge no. Removing that so only servers with scripts could have that? Plus those events are totally client related and the messages are never sent by the server, clients make them up. For all we know, the client could handle things differently later. And if you really want to do it, then just tell the players to disable events display, and do it fully by script...

    About the lowercase problem, it'd require more RAM so I'm not sure it's worth it. Also, how does it affect your scripts? If it's because you're reading the txt file from RAW, the txt file has never been intended for it...
     
  30. Mystra

    Mystra Active Member

    Joined:
    Jul 12, 2010
    Messages:
    1,389
    Likes Received:
    4
    @NeO:

    Code (text):
    1.  
    2. sys.sendAll("*** This message is blue").Color("Blue").Bold();
    3.                                        ^
    4.  
    At this place sendAll() was already called — too late. sendAll() accepts only plain text. If I change it to accept rich text then all current scripts will need to be changed to escape text they are writing. I don't think it is a good idea to break it like that.
     
  31. coyotte508

    coyotte508 Well-Known Member Administrator Server Owner Administrator Server Owner

    Joined:
    Apr 21, 2010
    Messages:
    6,363
    Likes Received:
    168
    Well there could be sys.sendHtml(....) Astruvis made the same request.

    But a new command needs to be added to the network protocol then.
     
  32. Mystra

    Mystra Active Member

    Joined:
    Jul 12, 2010
    Messages:
    1,389
    Likes Received:
    4
    Hmm… Are you sure it wouldn't be a security risk for users with this? Like with inserting scripts and images (if that is possible at all in the current chat log).
     
  33. Lutra

    Lutra All Gen Battler/Scripter

    Joined:
    Apr 25, 2010
    Messages:
    509
    Likes Received:
    188
    PO Trainer Name:
    Lutra
    You can't retrieve a player's name in the correct mixture of upper and lower case before the script starts recording (extra scripting). So if I wanted to list players that were in the db but were before the recording, their names would be in lower case. Which makes that list imperfect until all those players (without entire lower case names) log on (if they do).
     
  34. coyotte508

    coyotte508 Well-Known Member Administrator Server Owner Administrator Server Owner

    Joined:
    Apr 21, 2010
    Messages:
    6,363
    Likes Received:
    168
    Well that's the same with the rankings, the control panel, the server's player window, ... So it's not script related. And as I said, I never intended the db files to be read by scripts, so I don't "have" to provide any support for that.

    Now that the database is handled by SQL i'd need to learn about case insensitivity's impact on performance, and then change every line if there's no impact... Not sure I want to do that now ^^
     
  35. Mystra

    Mystra Active Member

    Joined:
    Jul 12, 2010
    Messages:
    1,389
    Likes Received:
    4
    @Lutra: WONTFIX for now. Auth change event is possible but its usefulness is questionable. Well, unless someone else will do it (^ ^)
     
  36. nesan

    nesan Love is blind

    Joined:
    Jun 13, 2010
    Messages:
    241
    Likes Received:
    0
    Um..like appendToFile and stuff, is it possible to make one for deleting files? o-o
     
  37. Mystra

    Mystra Active Member

    Joined:
    Jul 12, 2010
    Messages:
    1,389
    Likes Received:
    4
    @nesan: technically yes, practically I'm against it (^ ^) Why do you need it? Use writeToFile() and rewrite it.
     
  38. nesan

    nesan Love is blind

    Joined:
    Jun 13, 2010
    Messages:
    241
    Likes Received:
    0
    Yea, you're right.
    I hate using registry values. Writing files seems easier. lol
    It would be nice if we can delete files. xD
     
  39. coyotte508

    coyotte508 Well-Known Member Administrator Server Owner Administrator Server Owner

    Joined:
    Apr 21, 2010
    Messages:
    6,363
    Likes Received:
    168
    I added sys.changeDbAuth(name, auth) and sys.dbAuths() at someone's request.

    First changes the auth of someone in the db, second provides a list of names of people whose auth is superior to 0.
     
  40. Mystra

    Mystra Active Member

    Joined:
    Jul 12, 2010
    Messages:
    1,389
    Likes Received:
    4
    What's the difference between changeAuth() and changeDbAuth()?
     
Thread Status:
Not open for further replies.