Snippet Conversion and Finding Snippet Pack

Nestharus

o-o
Reaction score
84
A variety of very helpful snippets. I came up with all of these on my own except for two. One of the two is a common modular conversion and the other is a common search =P.

I will continue to add to this list as I think up other good algorithms and what not ^_^.

Conversions
JASS:
Functions for converting numbers into ids for arrays
----------------------------------------------------------------
//r is some arbitrary real number
//base is the base and should be under 1
//This is the most accurate way : )
private function Real2Id takes real r, real base returns integer
    return R2I((r/base)-R2I((r/base)/8191)*8191)
endfunction

//If the real is less than or equal 1, it will return 1, etc.
private function Real2Id takes real r returns integer
    return R2I(r-R2I(r/8191)*8191)
endfunction

//The most simple converter ever : ).
private function Integer2Id takes integer i returns integer
    return i-R2I(i/8191)*8191
endfunction
----------------------------------------------------------------

//Nice conversion function from BS. It will convert what you put it into
//the specified base first and then it will round it up if the remainder is over 0 and then
//convert it back to standard base 10 giving you a number that fits perfectly : ). It's useful
//for building timers or going through a series of numbers that follow a pattern ^_^.
private function Convert takes real r, real base returns real
    local real converted
    local integer rounded
    if r > base then
        set converted = r/base
        set rounded = R2I(converted)
        return (R2I(converted-rounded+.999)+roundedTime)*base //this will round up if it's above the base
        //or
        return (R2I(converted-rounded)+roundedTime)*base //this will always round down if above the base
    endif
    return base
endfunction


Searches
JASS:
//This will either find a current variable or find a new one. Use id
//conversions to get the proper start id.
//This is meant to go through some sort of an array given a value to find.
//If it runs into 0, it knows that the value does not exist and returns
//a new id ^_^. Use a conversion function to get the id to start the
//search.
private function Find takes integer id, real find returns integer
    loop
        exitwhen var[id] == find or var[id] == 0
        set id = id + 1
    endloop
    return id
endfunction

//The Super Dynamic Arrays <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite8" alt=":D" title="Big Grin    :D" loading="lazy" data-shortname=":D" />.. bit complicated : P
//Jesus4Lyf uses arrays similar to this one : ).
nextCode refers to the next code to go to
lastCode refers to the previous code to go to
currentCode refers to the currentCode and uses the array&#039;s id so it is always accessible

the functions to use are
NextCode- For looping
RemoveCode- for removing from an array
StreamCodeList- for adding to an array

So why is this array so dynamic? Well, let&#039;s say you have a single array and you want
a multi dimensional array in it. Well, one way is to make it static, meaning you have a
set number of positions etc like 50 positions in the first dimension and 50 slots per thingie ^_^.
Well, this will make the array fully dynamic meaning it could be anything from a 1 dimensional array to a
2 dimensional array with 40 dimensions and 20 slots per thingie. Very useful for when you&#039;re not sure what
you want to do or you want to leave it open.

    private constant function CHECK_NEXT_CODE takes integer id returns boolean //checks to see if the next code exists
        return (nextCode[codeStackLoop[id]] &gt; 0)
    endfunction
    
    private function NextCode takes integer id returns integer //loops through the array from start to finish and back
        local integer result = codeStackLoop[id]
        if CHECK_NEXT_CODE(id) then
            set codeStackLoop[id] = nextCode[codeStackLoop[id]]
        elseif not CHECK_NEXT_CODE(id) then
            set codeStackLoop[id] = firstCode[id]
        endif
        return codeStack[result]
    endfunction
    
    private function AddToCodeStackQueu takes integer stack returns nothing //adds to a queu for freed array indexes
        set codeStackQueuIndex = codeStackQueuIndex + 1
        set codeStackQueu[codeStackQueuIndex] = stack
    endfunction
    
    private function RemoveCodeFromStack takes integer id, integer stack returns integer //removes an index from the array
        local integer recycled = currentCode[id]
        if stack &lt; currentCode[id] then
            set codeStack[stack] = codeStack[currentCode[id]]
            set codePointToStack[codeStack[stack]] = stack
        endif
        set nextCode[lastCode[currentCode[id]]] = 0
        set lastCode[currentCode[id]] = 0
        set currentCode[id] = currentCode[id] - 1
        return recycled
    endfunction
    
    private function RemoveCode takes integer id, integer codeId returns nothing //removes code from the array
        call AddToCodeStackQueu(RemoveCodeFromStack(id, codePointToStack[codeId]))
        set codePointToStack[codeId] = 0
    endfunction
    
    private function CodeStackIndex takes integer id returns integer //attempts to get a recycled index
        if codeStackQueuIndex &gt; 0 then
            set codeStackQueuIndex = codeStackQueuIndex - 1
            return codeStackQueu[codeStackQueuIndex+1]
        endif
        return 0
    endfunction
    
    private function GetCodeStackIndex takes integer id returns integer //gets an index
        local integer instancedIndex = CodeStackIndex(id)
        if instancedIndex == 0 then
            set codeStackIndex = codeStackIndex + 1
            return codeStackIndex
        endif
        return instancedIndex
    endfunction
    
    private function NewCode takes integer id returns integer //creates new index
        local integer instancedIndex = GetCodeStackIndex(id)
        set lastCode[instancedIndex] = nextCode[lastCode[currentCode[id]]]
        set nextCode[lastCode[instancedIndex]] = instancedIndex
        set currentCode[id] = instancedIndex
        return instancedIndex
    endfunction
    
    private function StreamCodeList takes integer codeId, integer id returns nothing //the main function that is called ^_^
        local integer instancedIndex
        if currentCode[id] &gt; 0 then
            set instancedIndex = NewCode(id)
        else
            set instancedIndex = GetCodeStackIndex(id)
            set firstCode[id] = instancedIndex
            set currentCode[id] = instancedIndex
            set lastCode[currentCode[id]] = instancedIndex
            set nextCode[currentCode[id]] = instancedIndex
            set codeStackLoop[id] = firstCode[id]
        endif
        set codeStack[instancedIndex] = codeId
        set codePointToStack[codeId] = instancedIndex
    endfunction
 

UndeadDragon

Super Moderator
Reaction score
447
Why did you comment the whole code?
 

Renendaru

(Evol)ution is nothing without love.
Reaction score
309
Delimited comments no less.
 

Nestharus

o-o
Reaction score
84
Not delimited, but those codes aren't standalone. They are algorithms and patterns that are useful in map design : ).

I guess I can uncomment them if it'll be easier to read : P.
 

uberfoop

~=Admiral Stukov=~
Reaction score
177
//If the real is less than or equal 1, it will return 1, etc.
No it doesn't. Anyone can see that all that function does is truncate.



Also:
-Why are these two groups of functions together?
-Document better. What is the use of the different modular conversion functions? Why do we need all of them? What is the search pack for? Has anyone really been far even as decided to use even go want to do look more like? Pretty much.
 

Nestharus

o-o
Reaction score
84
Why are these two groups of functions together?

Searchers and converters work hand in hand : ).

What is the use of the different modular conversion functions?

Whenever you want to convert them into some sort of Id? dif ones for dif types of Ids ^_^. I used the bigger one for converting time : ).

Why do we need all of them?

You don't =). It's just a whole slew of snippets that are common ^^.

What is the search pack for

Well, for searching. The first is a normal find function that can be used with the converters to get the search going as quickly as possible : ). The second splits arrays up dynamically and is uhm... while I was writing it originally I was like Oo. All I can say is next is next and last is last and current is current ^_^.

The 2 functions to be used with the super dynamic arrays are-
StreamCodeList (put something into the array)
RemoveCode(removes something from the array)
NextCode (loop through the array)
 

uberfoop

~=Admiral Stukov=~
Reaction score
177
Don't just answer my post, I mean write up some documentation. Say what this is FOR.


You obviously haven't put much effort into that, considering that your code even has 3 uncommented comment lines as basically the entire documentation.

JASS:

//The Super Dynamic Arrays <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite8" alt=":D" title="Big Grin    :D" loading="lazy" data-shortname=":D" />.. bit complicated : P
//Jesus4Lyf uses arrays similar to this one : ).
nextCode refers to the next code to go to
lastCode refers to the previous code to go to
currentCode refers to the currentCode and uses the array&#039;s id so it is always accessible





You also still haven't explained why your second conversion function does the exact same thing as return R2I(r). It doesn't even do that it says it does.
 

Jesus4Lyf

Good Idea™
Reaction score
397
Has anyone really been far even as decided to use even go want to do look more like?
I'd have to agree. <3

JASS:
//The most simple converter ever : ).
private function Integer2Id takes integer i returns integer
    return i-R2I(i/8191)*8191
endfunction

If it's so simple, how did you frak it up?
JASS:
//Let&#039;s call it what it is!
private function ModuloPositiveIntBy8191 takes integer i returns integer
    return i-(i/8191)*8191
endfunction

I'm going to graveyard this because it doesn't serve a direct, simple purpose, it is just a collection of random code, each piece being strangely useless in its own right.

People should write these things themselves. Helps them understand it.
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • 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 The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top