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.

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top