Snippet Real Groups

D.V.D

Make a wish
Reaction score
73
Thanks to Aziler for helping me store reals in structs.

JASS:
library RealGroups initializer Init

//================================================================\\
// Real Groups Created By D.V.D                                   \\
//================================================================\\
// Purpose:                                                       \\
// To store and return unlimited amounts of reals instead of      \\
// making another function call for every real you want to return \\
//================================================================\\
// Pros:                                                          \\
// -Allows you to store and manipulate reals in real groups       \\
// -Replacing and copying real groups                             \\
// -Makes life easier for certian systems                         \\
// -Can be used instead of structs to store reals for abilities   \\
//================================================================\\
// method create takes nothing returns realgroup                  \\
// -Creates a real group                                          \\
//                                                                \\
// method addreal takes real r returns nothing                    \\
// -Adds a real to the real group increasing the count            \\
//                                                                \\
// method copyrealgroup takes nothing returns realgroup           \\
// -Copies and creates a new realgroup                            \\
//                                                                \\
// method getreal takes integer count returns nothing             \\
// -Gets a real from the real group by getting the reals count    \\
//                                                                \\
// method getrealnumber takes nothing returns integer             \\
// -Gets the amount of reals in a realgroup                       \\
//                                                                \\
// method cleargroup takes nothing returns nothing                \\
// -Clears all the reals from a realgroup. Does not destroy       \\
//                                                                \\
// method removereal takes integer count returns nothing          \\
// -Removes a real numberd by the count                           \\
//                                                                \\
// method replace real takes integer coun, real r returns nothing \\
// -Replaces a real counted by count with a new real              \\
//                                                                \\
// method mathallreals takes integer math returns nothing         \\
// -Adds,Subtracts,Multiplies, or Divides all reals. The values   \\
// are 0 = add, 1 = subtract, 2 = multiply, 3 = divide            \\
//                                                                \\
// method setallreals takes real r returns nothing                \\
// -Sets all reals in a group to a certian value                  \\
//                                                                \\
// method destroy takes nothing returns nothing                   \\
// -Destroys the real group                                       \\                                                               \\
//================================================================\\

    struct realgroup
        hashtable h
        integer count
        
        static method create takes nothing returns realgroup
            local realgroup g = realgroup.allocate()
            set g.h = InitHashtable()
            set g.count = 0
            return g
        endmethod
        
        method addreal takes real r returns nothing
            set .count = .count + 1
            call SaveReal( .h, .count, this, r )
        endmethod
        
        method copyrealgroup takes nothing returns realgroup
            local integer i = 0
            local real r
            local realgroup g = realgroup.allocate()
            
            loop
                exitwhen i > .count
                set r = LoadReal( .h, i, this)
                call g.addreal(r)
                set i = i + 1
            endloop
            return g
        endmethod
        
        method getreal takes integer count returns real
            return LoadReal(.h, count, this)
        endmethod
        
        method getrealnumber takes nothing returns integer
            return .count
        endmethod
        
        method cleargroup takes nothing returns nothing
            local integer i = 0
            local real r
            
            loop
                exitwhen i > .count
                set r = LoadReal(.h, i, this)
                set i = i + 1
            endloop
        endmethod
        
        method removereal takes integer count returns nothing
            local real r = LoadReal( .h, count, this )
            call RemoveSavedReal( .h, .count, this )
            set .count = .count - 1
        endmethod
        
        method replacereal takes integer count, real r returns nothing
            call SaveReal(.h, count, this, r )
        endmethod
        
        method mathallreals takes integer math, real p returns nothing
            local integer i = 0
            local real r
            
            loop
                exitwhen i > .count
                if ( math == 0 ) then //add
                    set r = LoadReal(.h, i, this)
                    set r = r + p
                    call SaveReal( .h, i, this, r )
                    elseif ( math == 1 ) then //subtract
                        set r = LoadReal(.h, i, this)
                        set r = r - p
                        call SaveReal( .h, i, this, r )
                    elseif ( math == 2 ) then //multiply
                        set r = LoadReal(.h, i, this)
                        set r = r * p
                        call SaveReal( .h, i, this, r )
                    elseif ( math == 3 ) then //divide
                        set r = LoadReal(.h, i, this)
                        set r = r / p
                        call SaveReal( .h, i, this, r )
                endif
                set i = i + 1
            endloop
        endmethod
        
        method setallreals takes real r returns nothing
            local integer i = 0
            
            loop
                exitwhen i > .count
                set r = LoadReal(.h, i, this)
                call .replacereal(i, r)
                set i = i + 1
            endloop
        endmethod
        
    endstruct

//===========================================================================
    function Init takes nothing returns nothing
        local trigger t = CreateTrigger(  )
    endfunction

endlibrary
 

Azlier

Old World Ghost
Reaction score
461
I hate the method names, the name of the script itself (Real Groups?!), the unprefixed Init function that does nothing but leak a trigger, the undescriptive names of method, the inefficiency of the mathallreals method, the public struct members...

>Aziler
BLAHSHTASKHBFRAGGEM
 

Renendaru

(Evol)ution is nothing without love.
Reaction score
309
I hate the method names, the name of the script itself (Real Groups?!), the unprefixed Init function that does nothing but leak a trigger, the undescriptive names of method, the inefficiency of the mathallreals method, the public struct members...

>Aziler
BLAHSHTASKHBFRAGGEM

It seems everyone started releasing things the same time I made IntegerGroups, which I can no longer submit. It would be GY'd instantly being seen as 'un-original'.
 

uberfoop

~=Admiral Stukov=~
Reaction score
177
The only uses I can think of for mathallreals are ones in which a simple real variable would serve far better.

In terms of syntax, it's harder to use and has less functionality than a unit group.

In terms of attachment, I'd rather use a more inlined and less cryptic method. Like several members. Or array members. Or just a direct hashtable call.
 

D.V.D

Make a wish
Reaction score
73
I hate the method names, the name of the script itself (Real Groups?!), the unprefixed Init function that does nothing but leak a trigger, the undescriptive names of method, the inefficiency of the mathallreals method, the public struct members...

>Aziler
BLAHSHTASKHBFRAGGEM

The Init function is supposed to be Map Initialization but there is no function for Map Init so its just blank. Whats so abd about the code? Helping me fix it would be much more convinient and I wouldn't repeat the same mistake again.

It seems everyone started releasing things the same time I made IntegerGroups, which I can no longer submit. It would be GY'd instantly being seen as 'un-original'.

I made this cause I needed to return a uncertian but large amount of reals and making many functions wasn't a good choice.

The only uses I can think of for mathallreals are ones in which a simple real variable would serve far better.

In terms of syntax, it's harder to use and has less functionality than a unit group.

In terms of attachment, I'd rather use a more inlined and less cryptic method. Like several members. Or array members. Or just a direct hashtable call.

Obviously it has less functionality than a unit group. There is as far as I know, no possibility to manually make a custom ForGroup function simply cause you can't add thestructs data to a unknown function in a different trigger. How is my code cryptic?
 

uberfoop

~=Admiral Stukov=~
Reaction score
177
Obviously it has less functionality than a unit group. There is as far as I know, no possibility to manually make a custom ForGroup function simply cause you can't add thestructs data to a unknown function in a different trigger.
Well, technically, you can. It's just not practical for many things.

How is my code cryptic?
I mean in comparison to direct hashtable use or use through a hashtable-wrapping system.
For example, if you're just attaching reals to something, this is nothing but an overkill and overly specific wrapper system.

By the way, why is there randomly a realgroup member of realgroup?
 

D.V.D

Make a wish
Reaction score
73
Forgot to remove that. Updated. And if you want more functionality, tell me some functions you would want me to add in?
 

Jesus4Lyf

Good Idea™
Reaction score
397
Thanks to Aziler for helping me store reals in structs.
You spelled his name wrong and still haven't corrected it.
The Init function is supposed to be Map Initialization but there is no function for Map Init so its just blank.
Then make it blank, not leak a trigger.
Whats so abd about the code?
the method names, the name of the script itself (Real Groups?!), the unprefixed Init function that does nothing but leak a trigger, the undescriptive names of method, the inefficiency of the mathallreals method, the public struct members...
He gave you a pretty good list, I thought.
I made this cause I needed to return a uncertian but large amount of reals and making many functions wasn't a good choice.
Try to make your system/snippet generally useful. If you think that nobody can use your system/snippet, don't submit it.
Good on you for making something useful for yourself, but aside from your own use, I think that nobody can use your snippet.

Graveyard.

Edit: For your own use, I recommend you take this back to JASS Help and get some opinions on the code (which I just looked at).
 

Darthfett

Aerospace/Cybersecurity Software Engineer
Reaction score
615
// To store and return unlimited amounts of reals instead of \\
// making another function call for every real you want to return \\

The only time I've ever needed to get multiple reals, is when I was working with x and y, and there's always another way to do it. Not really something I'd import a hashtable system into my map for.

JASS:
// method mathallreals takes integer math returns nothing         \\

Not really a great name, and if you want to use an integer argument to refer to the operators, I suggest you make constants to give the operators names, such as:

JASS:
globals
    constant integer OPERATOR_ADD = 0
    constant integer OPERATOR_SUBTRACT = 1
    constant integer OPERATOR_MULTIPLY = 2
    constant integer OPERATOR_DIVIDE = 3
englobals


// Pros: \\
// -Allows you to store and manipulate reals in real groups \\
// -Replacing and copying real groups \\
// -Makes life easier for certian systems \\
// -Can be used instead of structs to store reals for abilities \\

-Why is this good/bad? Give us an example of where this would be needed.
-I've never needed something like this, where would this be useful?
-But it would probably make the system slower, and make the user-interface a pain to work with.
-Structs are faster and simpler than hashtables.

You should give your methods better names, and make the naming follow camel notation conventions. Making every single word and letter all lower-case makes it hard to read and ugly to use.

JASS:
// method getrealnumber takes nothing returns integer             \\
// -Gets the amount of reals in a realgroup                       \\

Considering a real is a number, this isn't a very descriptive name. What about getRealCount?

// method getreal takes integer count returns nothing \\
// -Gets a real from the real group by getting the reals count \\

Your description doesn't really make sense. I think what you mean to say is that it gets the real from the group that is stored in the 'count' memory location.

You also are creating a useless trigger in the Init function, why did you do this?
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • WildTurkey WildTurkey:
    is there a stephen green in the house?
    +1
  • The Helper The Helper:
    What is up WildTurkey?
  • The Helper The Helper:
    Looks like Google fixed whatever mistake that made the recipes on the site go crazy and we are no longer trending towards a recipe site lol - I don't care though because it motivated me to spend alot of time on the site improving it and at least now the content people are looking at is not stupid and embarrassing like it was when I first got back into this like 5 years ago.
  • The Helper The Helper:
    Plus - I have a pretty bad ass recipe collection now! That section of the site is 10 thousand times better than it was before
  • The Helper The Helper:
    We now have a web designer at my job. A legit talented professional! I am going to get him to redesign the site theme. It is time.
  • Varine Varine:
    I got one more day of community service and then I'm free from this nonsense! I polished a cop car today for a funeral or something I guess
  • Varine Varine:
    They also were digging threw old shit at the sheriff's office and I tried to get them to give me the old electronic stuff, but they said no. They can't give it to people because they might use it to impersonate a cop or break into their network or some shit? idk but it was a shame to see them take a whole bunch of radios and shit to get shredded and landfilled
  • The Helper The Helper:
    whatever at least you are free
  • Monovertex Monovertex:
    How are you all? :D
    +1
  • Ghan Ghan:
    Howdy
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top