View Poll Results: Should mobile attributes be used?

Voters
7. You may not vote on this poll
  • Yes, it helps manage temporary values

    6 85.71%
  • No, it just hides properties

    0 0%
  • I am unsure / other reason (please specify)

    1 14.29%

Thread: Benefits of an attribute system?

Results 1 to 8 of 8
  1. #1 Benefits of an attribute system? 
    Registered Member
    Join Date
    Jan 2022
    Posts
    49
    Thanks given
    1
    Thanks received
    10
    Rep Power
    11
    Hi guys,

    So many servers seem to have an attribute system defined on Mobile class (Player / NPC). This is used for defining temporary or "soft" properties that may or may not exist.
    I guess the benefit is the class becomes less cluttered, but what is your opinion on it? Is it bad practice because these are basically now just hidden class members?
    Or is it convenient because you may/may not have to define these properties before their used.
    Or is it good to reduce the need for having getters/setters for every simple property?
    Or am I missing another reason?

    Example:
    Code:
    player.<Boolean>getAttributeOr(AttributeKey.DEFENSIVE_AUTOCAST, false)
    This determines whether the player has selected to use Defensive autocast mode or regular autocast mode.

    The code to set this attribute would be:
    Code:
    player.putAttribute(AttributeKey.DEFENSIVE_AUTOCAST, true);
    Here's me implementing this into our core repo (feel free to copy and paste if you like):
    https://github.com/RSPSApp/elvarg-rsps/pull/65/files

    Edit: Since Spooky mentioned varps and I hadn't a clue what they were (don't judge me), here's a link:
    What are varps and varbits?
    Reply With Quote  
     

  2. #2  
    L O S E Y O U R S E L F
    Format's Avatar
    Join Date
    Aug 2013
    Posts
    2,311
    Thanks given
    1,131
    Thanks received
    1,461
    Rep Power
    5000
    Its good for storing and handling on-demand / temporary data. Otherwise you will be storing alot of "attribute" variables against a user which can get pretty heavy and cluttered if they aren't necessarily used all the time.

    E.g. if a player never ends up equipping magic weapons - why would you have permanent variables stored against the player in relation to it.


    In my own opinion - its alot more efficient, especially if you start getting a larger player base taking up alot of memory.


    Reply With Quote  
     

  3. #3  
    Registered Member
    Join Date
    Jan 2022
    Posts
    49
    Thanks given
    1
    Thanks received
    10
    Rep Power
    11
    Quote Originally Posted by Format View Post
    I guess its good for storing and handling on-demand / temporary data. Otherwise you will be storing alot of "attribute" variables against a user which can get pretty heavy and cluttered if they aren't necessarily used all the time.

    E.g. if a player never ends up equipping magic weapons - why would you have a permanent variables stored against the player in relation to it.
    Very good point, I didn't think about that scenario. I guess its all about balance like other things. I did see one server source that had probably over 100 attribute keys defined. Which got me thinking
    Reply With Quote  
     

  4. #4  
    L O S E Y O U R S E L F
    Format's Avatar
    Join Date
    Aug 2013
    Posts
    2,311
    Thanks given
    1,131
    Thanks received
    1,461
    Rep Power
    5000
    Quote Originally Posted by RspsApp View Post
    Very good point, I didn't think about that scenario. I guess its all about balance like other things. I did see one server source that had probably over 100 attribute keys defined. Which got me thinking
    Yeah, I personally feel that when you start getting a list that big you should definitely have some sort of dynamic handling system in place. Which is why this attribute system works well in this scenario. Also decouples the code alot neater aswell.


    Reply With Quote  
     

  5. #5  
    Respected Member


    Join Date
    Jan 2009
    Posts
    5,743
    Thanks given
    1,162
    Thanks received
    3,603
    Rep Power
    5000
    It's not just for temporary attributes but those which persist also... 99% of types that'll you'll persist will be varps or could be varps of some sort, so probably easier to just use varps to begin with and have an attribute for which are transmittable and which ones are not... this unclutters the clusterfuck of the player class most servers have and makes saving only a couple of lines...
    Reply With Quote  
     

  6. Thankful users:


  7. #6  
    Registered Member
    Join Date
    Jan 2022
    Posts
    49
    Thanks given
    1
    Thanks received
    10
    Rep Power
    11
    Quote Originally Posted by Spooky View Post
    It's not just for temporary attributes but those which persist also... 99% of types that'll you'll persist will be varps or could be varps of some sort, so probably easier to just use varps to begin with and have an attribute for which are transmittable and which ones are not... this unclutters the clusterfuck of the player class most servers have and makes saving only a couple of lines...
    Very informative, thanks. I'm now currently researching varps and varbits
    Reply With Quote  
     

  8. #7  
    Endeavor

    Mikey`'s Avatar
    Join Date
    Dec 2007
    Posts
    4,434
    Thanks given
    715
    Thanks received
    1,435
    Rep Power
    1202
    It's good practice to have something like this for scripts so you have somewhere to store temporary or persistent data. Varps/varbits will cover a lot of cases but not all of them, item attributes come to mind. If you have small units of code for content scripts, that's where it makes sense to use attributes. I wouldn't use them for anything near the core because it limits your ability to encapsulate and getting/setting becomes verbose.
    Reply With Quote  
     

  9. #8  
    Banned


    Join Date
    Jul 2020
    Posts
    157
    Thanks given
    100
    Thanks received
    166
    Rep Power
    0
    Quote Originally Posted by RspsApp View Post
    ....
    I use them for Items mostly like charges ect, but they are nice on players and npcs also. its a rlly nice way to get rid a load of variables when they ain't needed direct on the player
    Reply With Quote  
     


Thread Information
Users Browsing this Thread

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


User Tag List

Similar Threads

  1. Changing the max amount of an Item
    By Elid in forum Tutorials
    Replies: 10
    Last Post: 10-06-2008, 10:58 AM
  2. Replies: 9
    Last Post: 07-30-2008, 08:23 AM
  3. Replies: 13
    Last Post: 04-15-2008, 05:11 PM
  4. Recoloring as many parts of an item as you want
    By Scottyz in forum Tutorials
    Replies: 4
    Last Post: 01-08-2008, 01:30 AM
  5. Remake of an old sig
    By Purefire in forum Showcase
    Replies: 2
    Last Post: 12-19-2007, 03:03 PM
Tags for this Thread

View Tag Cloud

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