User Tag List

Page 1 of 2 1 2 LastLast
Results 1 to 10 of 14

Thread: Script Counters Roll Over to Max Int When Going Below Zero

  1. #1
    Keese ywkls's Avatar
    Join Date
    Feb 2016
    Posts
    62
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)
    vBActivity - Stats
    Points
    283
    Level
    6
    vBActivity - Bars
    Lv. Percent
    19.62%
    Daily Activity
    0%
    Weekly Activity
    0.53%
    Monthly Activity
    0.48%

    Verified Bug Script Counters Roll Over to Max Int When Going Below Zero

    Something I noted in some of my scripts. (I don't know if this applies to just script counters, but that's where I saw this happen.)

    When the counter drops below zero for whatever reason, it rolls over to 65,535.
    Last edited by ZoriaRPG; 01-19-2017 at 03:59 PM.

  2. #2
    The Timelord
    ZC Developer
    ZoriaRPG's Avatar
    Join Date
    Oct 2006
    Location
    Prydon Academy
    Posts
    1,264
    Mentioned
    107 Post(s)
    Tagged
    1 Thread(s)
    vBActivity - Stats
    Points
    4,248
    Level
    20
    vBActivity - Bars
    Lv. Percent
    64.12%
    Daily Activity
    0%
    Weekly Activity
    19.9%
    Monthly Activity
    27.72%
    Quote Originally Posted by ywkls View Post
    Something I noted in some of my scripts. (I don't know if this applies to just script counters, but that's where I saw this happen.)

    When the counter drops below zero for whatever reason, it rolls over to 65,535.
    Please post a tiny sample quest that attempts to do this using whatever methods you know that have this issue, for each counter, so that we know which counters it affects, and precisely what is causing it.

    I mentioned this in the past, but everyone assured me that it was fixed?

    It should not be hard to write a handler to resolve this problem, although for the record, I think counters would be better as individual 32-bit width longs instead of 16-bit width ints.(This is to keep them in the same mathematical context as other ZC values.)

    Check also MCounter[] and DCounter[] please, as well as Link->MP and Link->HP, which IIRC should not do this because they do have handlers to prevent that sort of thing.


    Featured Scripts & Headers: RPG.zh ( v. a0.97.1 ) ( RPG.zh Thread ) | Zelda 3 Thief's Town Treasure Chest Minigame (ffc) | Bobomb (enemy)
    ZScript & ZC-Related Pastebin | Quests and ZScript Repository | ZC Dev & Betas | Latest ZC 2.55 Alpha | YouTube Channel
    All of the code that I create and publish here is free for use, modification and distribution under the GPL v2.0, or v3.0 where applicable..

  3. #3
    Is this the end?
    ZC Developer
    Saffith's Avatar
    Join Date
    Jan 2001
    Age
    35
    Posts
    3,366
    Mentioned
    174 Post(s)
    Tagged
    6 Thread(s)
    vBActivity - Stats
    Points
    6,137
    Level
    24
    vBActivity - Bars
    Lv. Percent
    20.77%
    Daily Activity
    0%
    Weekly Activity
    0.53%
    Monthly Activity
    1.27%
    I don't know if we would consider this a problem. Counters are uint16_t; that's just what they do. It's not unreasonable behavior. Maybe it's unexpected that the range is different than other numbers, but plenty of built-in things have different ranges.
    [téknolàiz]

    ffcscript.zh 1.1.1 - Updated 2014-08-19
    ghost.zh 2.8.2 - Updated 2017-09-10
    tango.zh 1.3.1 - Updated 2017-12-27

  4. #4
    The Timelord
    ZC Developer
    ZoriaRPG's Avatar
    Join Date
    Oct 2006
    Location
    Prydon Academy
    Posts
    1,264
    Mentioned
    107 Post(s)
    Tagged
    1 Thread(s)
    vBActivity - Stats
    Points
    4,248
    Level
    20
    vBActivity - Bars
    Lv. Percent
    64.12%
    Daily Activity
    0%
    Weekly Activity
    19.9%
    Monthly Activity
    27.72%
    Quote Originally Posted by Saffith View Post
    I don't know if we would consider this a problem. Counters are uint16_t; that's just what they do. It's not unreasonable behavior. Maybe it's unexpected that the range is different than other numbers, but plenty of built-in things have different ranges.
    Sure, but when scripts modify them without checking if the post-modufied sum exceeds their value limit, then they generate bus.

    The real problem is that ADDR/V don't care what they are writing here. AFAIK increasing a fix to > 214749.9999 doesn't roll it over to -214747.9999, does it?

    For a an int 16, it is normal, but in their application, rolling over is irrational, and only scripta can do it. Picking up counter ref items does not.

    I could add a check to prevent this behaviour in ZASM. Need to check if this will be problematic.


    Featured Scripts & Headers: RPG.zh ( v. a0.97.1 ) ( RPG.zh Thread ) | Zelda 3 Thief's Town Treasure Chest Minigame (ffc) | Bobomb (enemy)
    ZScript & ZC-Related Pastebin | Quests and ZScript Repository | ZC Dev & Betas | Latest ZC 2.55 Alpha | YouTube Channel
    All of the code that I create and publish here is free for use, modification and distribution under the GPL v2.0, or v3.0 where applicable..

  5. #5
    Username Kaiser SUCCESSOR's Avatar
    Join Date
    Jul 2000
    Location
    Winning.
    Age
    32
    Posts
    4,435
    Mentioned
    152 Post(s)
    Tagged
    7 Thread(s)
    vBActivity - Stats
    Points
    10,366
    Level
    30
    vBActivity - Bars
    Lv. Percent
    27.95%
    Daily Activity
    0%
    Weekly Activity
    0.53%
    Monthly Activity
    0.48%
    Quote Originally Posted by ZoriaRPG View Post
    Sure, but when scripts modify them without checking if the post-modufied sum exceeds their value limit, then they generate bus.

    The real problem is that ADDR/V don't care what they are writing here. AFAIK increasing a fix to > 214749.9999 doesn't roll it over to -214747.9999, does it?

    For a an int 16, it is normal, but in their application, rolling over is irrational, and only scripta can do it. Picking up counter ref items does not.

    I could add a check to prevent this behaviour in ZASM. Need to check if this will be problematic.
    o.O I don't know if I am tired from school and work but sometimes when you talk I can't wrap my head around what you are trying to say. Longs, Zscript variables, do indeed wrap if you exceed them. I know they have a funniness about them with the whole decimal thing it does, but... that's another bag of WTF. I don't know what behavior you'd want counters to have that would change the way they behave. I don't believe it would happen in game besides through scripting.

    If you are coding and setting a value to a variable without concern for what that variable can contain or what you are writing to it then you aren't coding very well.

  6. #6
    The Timelord
    ZC Developer
    ZoriaRPG's Avatar
    Join Date
    Oct 2006
    Location
    Prydon Academy
    Posts
    1,264
    Mentioned
    107 Post(s)
    Tagged
    1 Thread(s)
    vBActivity - Stats
    Points
    4,248
    Level
    20
    vBActivity - Bars
    Lv. Percent
    64.12%
    Daily Activity
    0%
    Weekly Activity
    19.9%
    Monthly Activity
    27.72%
    Quote Originally Posted by SUCCESSOR View Post
    o.O I don't know if I am tired from school and work but sometimes when you talk I can't wrap my head around what you are trying to say. Longs, Zscript variables, do indeed wrap if you exceed them. I know they have a funniness about them with the whole decimal thing it does, but... that's another bag of WTF. I don't know what behavior you'd want counters to have that would change the way they behave. I don't believe it would happen in game besides through scripting.

    If you are coding and setting a value to a variable without concern for what that variable can contain or what you are writing to it then you aren't coding very well.
    (Emphasis, mine.)

    Absolutely true. I check for these sorts of things whenever possible, but when people have a script like this:

    Code:
    item script foo{
        void run(int ctr){
            Game->Counter[ctr]++;
        }
    }
    ...and trust me, these about in the database...

    ...then it can cause rollover. It's illogical for a counter to roll over anyway. That's my real point. That, and the behaviour doesn't match internal counter ref behaviour from items, IIRC.

    ZScript fix values do indeed wrap, although the values generated are bizarre.

    214747 += 1 goes to 214748, and ++ again wraps to -214747.7296. ??? What?

    9999 - 3647 = 6352, not 7296. What is happening there?

    214748.3647 += .0001 wraps to -214748.3648.
    Last edited by ZoriaRPG; 01-20-2017 at 12:52 AM.


    Featured Scripts & Headers: RPG.zh ( v. a0.97.1 ) ( RPG.zh Thread ) | Zelda 3 Thief's Town Treasure Chest Minigame (ffc) | Bobomb (enemy)
    ZScript & ZC-Related Pastebin | Quests and ZScript Repository | ZC Dev & Betas | Latest ZC 2.55 Alpha | YouTube Channel
    All of the code that I create and publish here is free for use, modification and distribution under the GPL v2.0, or v3.0 where applicable..

  7. #7
    They Live We Sleep ZC Developer
    Gleeok's Avatar
    Join Date
    Apr 2007
    Posts
    4,773
    Mentioned
    255 Post(s)
    Tagged
    10 Thread(s)
    vBActivity - Stats
    Points
    12,641
    Level
    32
    vBActivity - Bars
    Lv. Percent
    92.14%
    Daily Activity
    0%
    Weekly Activity
    0.53%
    Monthly Activity
    0.48%
    Rpgs have this problem. A base value is always expected to be in range 0:N, but modifiers are valid if < 0 or > N. Finally, final derived values are again expected to be within range of 0 to N when the dust settles. (This is not the case with statistical values but ZC doesn't have those. ) I would assume that setting a counter (with implicit positive range) to -1 would set it to 0 and not 65535.

    What are all the counters affected by this?
    "Protocols of the Learned Elders of Zion" (British Royal Institute, 1906)
    "The International Jew: The World's Foremost Problem" –Henry Ford
    "The Host and The Parasite — How Israel's Fifth Column Consumed America." –Greg Felton
    "War is a Racket" –Major General Smedley Butler
    "The Secret Destiny of America" –Manly P. Hall
    "America: The Farewell Tour" –Chris Hedges
    "A Strategy for Israel in the Nineteen Eighties" Oded Yinon (English Translation)
    The War You Don't Seery
    Psywar

    “The modern theory of the perpetuation of debt has drenched the earth with blood, and crushed its inhabitants under burdens ever accumulating.” –Thomas Jefferson
    “It is well enough that the people of the nation do not understand our banking and monetary system for, if they did, I believe there would be a revolution before tomorrow morning.” –Henry Ford
    “Man will ultimately be governed by God or by tyrants.” –Benjamin Franklin

    This post contains the official Gleeok™ seal of approval. Look for these and other posts in an area near you.

  8. #8
    Username Kaiser SUCCESSOR's Avatar
    Join Date
    Jul 2000
    Location
    Winning.
    Age
    32
    Posts
    4,435
    Mentioned
    152 Post(s)
    Tagged
    7 Thread(s)
    vBActivity - Stats
    Points
    10,366
    Level
    30
    vBActivity - Bars
    Lv. Percent
    27.95%
    Daily Activity
    0%
    Weekly Activity
    0.53%
    Monthly Activity
    0.48%
    Quote Originally Posted by ZoriaRPG View Post
    (Emphasis, mine.)
    ...then it can cause rollover. It's illogical for a counter to roll over anyway. That's my real point. That, and the behaviour doesn't match internal counter ref behaviour from items, IIRC.
    Quote Originally Posted by Gleeok View Post
    Rpgs have this problem. A base value is always expected to be in range 0:N, but modifiers are valid if < 0 or > N. Finally, final derived values are again expected to be within range of 0 to N when the dust settles. (This is not the case with statistical values but ZC doesn't have those. ) I would assume that setting a counter (with implicit positive range) to -1 would set it to 0 and not 65535.

    What are all the counters affected by this?
    I would expect setting the counter directly through script for it to behave like the variable it is. I would expect that letting the game handle adjusting the counter to behave as it should.

    That's what we have drain counters, right?
    Last edited by SUCCESSOR; 01-20-2017 at 12:58 AM.

  9. #9
    Keese
    ZC Developer

    Join Date
    Jan 2007
    Age
    29
    Posts
    52
    Mentioned
    27 Post(s)
    Tagged
    1 Thread(s)
    vBActivity - Stats
    Points
    586
    Level
    8
    vBActivity - Bars
    Lv. Percent
    62.08%
    Daily Activity
    0%
    Weekly Activity
    0.53%
    Monthly Activity
    0.48%
    I just want to point out the one "common" case in which allowing negative hp would be beneficial, since I don't believe anybody's mentioned it:

    I've set up an elemental damage system where I encode the damage in the ones digit of the decimal damage number, and the actual damage in the higher digits. Then, every frame, you compare Link's hp to his hp in the previous frame. If he took damage, you can tell exactly what element it was, and adjust his hp to the correct amount based on weaknesses, etc.

    The problem hits when your hp gets too low to take the full damage from an attack. To get around this I add around 1000 hp to link to make sure it never goes negative - but this messes up the built-in hp meter, and the save file, and a whole bunch of other things, meaning you need custom scripts to handle all of them.

    Of course, my specific case is a bit complicated. But I've seen several other people (attempt to) use the "compare hp to last frame and then do something" strategy, that disallowing negative hp makes difficult. Ideally, the game would allow hp to go negative, but all the built-in aspects like the health meter and such would treat it as 0.

    I understand if y'all don't want to do that, though.

  10. #10
    The Timelord
    ZC Developer
    ZoriaRPG's Avatar
    Join Date
    Oct 2006
    Location
    Prydon Academy
    Posts
    1,264
    Mentioned
    107 Post(s)
    Tagged
    1 Thread(s)
    vBActivity - Stats
    Points
    4,248
    Level
    20
    vBActivity - Bars
    Lv. Percent
    64.12%
    Daily Activity
    0%
    Weekly Activity
    19.9%
    Monthly Activity
    27.72%
    Quote Originally Posted by SUCCESSOR View Post
    I would expect setting the counter directly through script for it to behave like the variable it is. I would expect that letting the game handle adjusting the counter to behave as it should.

    That's what we have drain counters, right?
    THat's true. I wish that people used them, but one reason they do not, is that say, you want to write Game->DCounter[CR_RIUPEES] -= 10000;

    Who long do you want to head that sound and watch the counter go down? Writing to Game->counter instantly applies the change.

    Let me try this: Who can make a case for rollover being useful, or beneficial, in the context of counters?
    @DarkDragon , @Grayswandir , and I all seem to agree that rollover in the counters is irrational.

    We can always make it a rule or setting. I could put it in ffrules[], or add a global bit for it. I just don;t see the point of doing that, unless there is a very good reason for it.

    Likewise, I would like to see cases against both longs as counters, and signed values; as I do not see an issue with any of these, based on what we now have. We already trim bits off of the word to make counters work with DCounter, which is signed.


    Featured Scripts & Headers: RPG.zh ( v. a0.97.1 ) ( RPG.zh Thread ) | Zelda 3 Thief's Town Treasure Chest Minigame (ffc) | Bobomb (enemy)
    ZScript & ZC-Related Pastebin | Quests and ZScript Repository | ZC Dev & Betas | Latest ZC 2.55 Alpha | YouTube Channel
    All of the code that I create and publish here is free for use, modification and distribution under the GPL v2.0, or v3.0 where applicable..

Thread Information

Users Browsing this Thread

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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
About us
Armageddon Games is a game development group founded in 1997. We are extremely passionate about our work and our inspirations are mostly drawn from games of the 8-bit and 16-bit era.
Social