User Tag List

Results 1 to 7 of 7

Thread: I want +=, -=, *=, /= and div

  1. #1
    Developer
    ZC Developer

    Join Date
    Aug 2006
    Location
    Australia
    Age
    37
    Posts
    2,777
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    vBActivity - Stats
    Points
    6,851
    Level
    25
    vBActivity - Bars
    Lv. Percent
    37.68%

    I want +=, -=, *=, /= and div

    See topic title. The first four would be helpful keystroke-savers, and the latter is useful when trying to work out how many 16s are in a sprite's y value.

  2. #2
    Administrator DarkDragon's Avatar
    Join Date
    Oct 2001
    Posts
    6,228
    Mentioned
    70 Post(s)
    Tagged
    0 Thread(s)
    vBActivity - Stats
    Points
    11,028
    Level
    31
    vBActivity - Bars
    Lv. Percent
    8.48%

    Re: I want +=, -=, *=, /= and div

    What does "div" do?

  3. #3
    Administrator DarkDragon's Avatar
    Join Date
    Oct 2001
    Posts
    6,228
    Mentioned
    70 Post(s)
    Tagged
    0 Thread(s)
    vBActivity - Stats
    Points
    11,028
    Level
    31
    vBActivity - Bars
    Lv. Percent
    8.48%

    Re: I want +=, -=, *=, /= and div

    Well in any case the following have been added to the ZScript language in b14:
    +=
    -=
    *=
    /=
    &&=
    ||=
    &=
    |=
    ^=
    <<=
    >>=
    %=

  4. #4
    Developer
    ZC Developer

    Join Date
    Aug 2006
    Location
    Australia
    Age
    37
    Posts
    2,777
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    vBActivity - Stats
    Points
    6,851
    Level
    25
    vBActivity - Bars
    Lv. Percent
    37.68%

    Re: I want +=, -=, *=, /= and div

    Div is integer division. Think of it as the counterpart to mod.

    Alternatively, you could add floor() (and ceiling()).

  5. #5
    Administrator DarkDragon's Avatar
    Join Date
    Oct 2001
    Posts
    6,228
    Mentioned
    70 Post(s)
    Tagged
    0 Thread(s)
    vBActivity - Stats
    Points
    11,028
    Level
    31
    vBActivity - Bars
    Lv. Percent
    8.48%

    Re: I want +=, -=, *=, /= and div

    I don't think adding those to the language itself is necessary, but I will add the following functions to std.zh, the ZScript standard header that will be included in b14:

    Code:
    //some utility routines
    int Floor(int x) {
    	if(x < 0)
    		return (x-.9999)<<0;
    	return x<<0;
    }
    
    int Ceiling(int x) {
    	if(x < 0)
    		return x<<0;
    	return (x+.9999)<<0;
    }
    std.zh will also include constants like SFX_STAIRS for sound effects and item classes.

  6. #6
    Patra Cloral's Avatar
    Join Date
    Apr 2001
    Location
    Ventura, CA
    Age
    41
    Posts
    8,589
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    vBActivity - Stats
    Points
    10,224
    Level
    30
    vBActivity - Bars
    Lv. Percent
    10.6%

    Re: I want +=, -=, *=, /= and div

    Actually div() would be a really useful function. Div would essentially be the equivalent of:
    Code:
    result = x / y;
    if(result > 0)
    {
      result = Floor(result);
    }
    else
    {
      result = Ceiling(result);
    }

  7. #7
    Administrator DarkDragon's Avatar
    Join Date
    Oct 2001
    Posts
    6,228
    Mentioned
    70 Post(s)
    Tagged
    0 Thread(s)
    vBActivity - Stats
    Points
    11,028
    Level
    31
    vBActivity - Bars
    Lv. Percent
    8.48%

    Re: I want +=, -=, *=, /= and div

    Added.

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