Snippet R-Functions

Rheias

New Helper (I got over 2000 posts)
Reaction score
232
Just a few simple function to help you do things faster - I'll keep this updated since every function that I will write and find useful I'll add here.

JASS:
// if SubString(l-1,l) is just annoying
function RF_IsEven takes integer subject returns boolean
    local integer check = subject / 2
    local integer test = check * 2
    
    if test < subject or subject < 2 then
        return false
    endif
    
    return true
endfunction

function RF_R2I takes real subject returns integer
    local real check = subject - .5
    local integer test = R2I(subject)
    
    if test >= check then
        return test
    endif
    
    return test + 1
endfunction

// Too bad we can't return two reals
function RF_Destination takes unit subject, real wait returns location
    local real facing = GetUnitFacing(subject)
    local real speed = GetUnitMoveSpeed(subject)
    local real distance = wait * speed
    local location current = GetUnitLoc(subject)
    local location returned = PolarProjectionBJ(current,distance,facing)

    // Leakz
    call RemoveLocation(current)
    set current = null
    
    return returned
endfunction

//Forced by WE - Not relevant
function InitTrig_RFunctions takes nothing returns nothing
endfunction


RF_IsEven - If an integer is even it will return true, else return false. 0 is considered odd (false).

RF_R2I - Converts a real to integer, however unlike the regular conversion, it won't be rounded down, but rounded to the closet integer (e.g. 3.1 = 3, 3.7 = 4). X.5 = X.

RF_Destination - Assuming the unit will keep walking in the same direction this will return the location it will reach after "wait" number of seconds.

Very little so far, but I hope soon enough more functions will be added, anyway, have fun with it.
 

Attachments

  • R-Functions.w3m
    12.4 KB · Views: 270

~GaLs~

† Ғσſ ŧħə ѕαĸε Φƒ ~Ğ䣚~ †
Reaction score
180
>>X.5 = X
arent .5 being rounded will become 1?
 

Rheias

New Helper (I got over 2000 posts)
Reaction score
232
What?

1.5 = 1 if you use my function. In the same manner:

2.5 = 2, 3.5 = 3, 4.5 =4 ... n.5 = n
 

Rheias

New Helper (I got over 2000 posts)
Reaction score
232
> AceHart

Hmmm... Care do explain what you want to say in that post? ;)

> Unverified

Are you quite sure this is a legitimate word?
 

Rheias

New Helper (I got over 2000 posts)
Reaction score
232
> That there's most likely an easy way to shorten those functions to one-liners.

Bah - those are too simple for my mind which likes to do things more complicated than they should.

> Yes.

Then it is not included in my dictionary.
 

~GaLs~

† Ғσſ ŧħə ѕαĸε Φƒ ~Ğ䣚~ †
Reaction score
180
my meaning is...

0.0, 0.1, 0.2, 0.3, 0.4 should be 0 when being rounded
0.5, 0.6, 0.7, 0.8, 0.9 should be 1 when being rounded...
 

Rheias

New Helper (I got over 2000 posts)
Reaction score
232
> 0.5, 0.6, 0.7, 0.8, 0.9 should be 1 when being rounded...
Today 05:13 PM

Then change the function, although AceHart pretty much ruined what I did here. :p

> See verify.

Bah, I tried verifie, thanks phyrex1an, you learn something new every day. ;)
 

Master

Thou shall be helped by...The Black Adder!
Reaction score
72
Well nothin's ruined...it's quite good, Rheias +rep.

You are incompetable.

Look in dictionary -> incompetability
 

Ghan

Administrator - Servers are fun
Staff member
Reaction score
889
> RF_IsEven - If an integer is even it will return true, else return false. 0 is considered odd (false).

This can be accomplished very simply using the mod function.

JASS:
if (<Number> Mod 2) Equal to 0, Then
  return true
else
  return false


That just seems a little simpler.
As for the other stuff, looks pretty good.
 

AceHart

Your Friendly Neighborhood Admin
Reaction score
1,495
> That just seems a little simpler.

Once there, you notice that, basically, you're returning the result of the test, so you return the test directly and forget the "if".
At which point you can do the mod yourself, and end up with post #4.
 

Rheias

New Helper (I got over 2000 posts)
Reaction score
232
My function (IsEven) is basically a (very) fancy way of doing AceHart's job. As for your function, it may be a bit shorter (note that my function is long in order to make it clear) but I'm not sure it is efficient as mine (no function calls in mine, in yours there is one,which is quite slow).

Anyway, this is supposed just to be kind of a bank for functions, I hope the next ones would be more useful. ;)
 

SerraAvenger

Cuz I can
Reaction score
234
Just a few simple function to help you do things faster - I'll keep this updated since every function that I will write and find useful I'll add here.

JASS:
// if SubString(l-1,l) is just annoying
function RF_IsEven takes integer subject returns boolean
    local integer check = subject / 2
    local integer test = check * 2
    
    if test < subject or subject < 2 then
        return false
    endif
    
    return true
endfunction


RF_IsEven - If an integer is even it will return true, else return false. 0 is considered odd (false).

I'ld use
JASS:
if subject - (subject / 2) * 2 == 0 then
.

EDIT: didn't read aceharts post, sorry.

EDIT2: You can aswell write these functions in your map header. Then you aren't forced by WE to make a trigger init function. On second thought - in which way does WE force you to copy the WHOLE page, and not to skip the last two ( three ) lines?
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • 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
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +2
  • V-SNES V-SNES:
    Happy Friday!
    +1

      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