Jass actions and Jasscraft (was: Ninja_Sheeps Jass-Question thread.)

Duwenbasden

Ver 6 CREATE energy AS SELECT * FROM u.energy
Reaction score
165
Did you understand what I said? You cannot compare equality between two real numbers. As soon as it is type Real == any number type, it will never work.

Code:
local real Random_Number = GetRandomReal(1.00, 3.00)

Instead of that, use this (you have no choice):
Code:
local integer Random_Number = GetRandomInt(1, 3)
if Random_Number == 3 then
  //...

Real uses more memory too.
 

PurgeandFire

zxcvmkgdfg
Reaction score
509
Did you understand what I said? You cannot compare equality between two real numbers. As soon as it is type Real == type Real, it will never work.

Code:
local real Random_Number = GetRandomReal(1.00, 3.00)

Instead of that, use this (you have no choice):
Code:
local integer Random_Number = GetRandomInt(1, 300)

Hm... So is the code trying to get it so that it gives like a 3/200 (Something like that) chance of getting those numbers? Because it only modifies to 1.00, 2.00, and 3.00. If you wish for it to do only 3 numbers, then you must have it as an integer but instead from 1 to 3, otherwise you can use what Duwenbasden said.
 

Duwenbasden

Ver 6 CREATE energy AS SELECT * FROM u.energy
Reaction score
165
no, :
Code:
Random_Number=R2I(GetRandomReal(1.00, 3.00))
This line did a random number between 1.00 - 3.00, then converts it to integer with floor (1.99 -> 1, 2.01 -> 2); then converts it back to real (if it is 2, then converted to something between 1.999###... - 2.000...##...)
 

SFilip

Gone but not forgotten
Reaction score
634
> As soon as it is type Real == any number type, it will never work.
You sure?
JASS:
function realtest takes nothing returns nothing
    local real test = 50.2
    if test == 50.2 then
        call BJDebugMsg("1")
    endif
endfunction

Displays 1 on screen after you call it.
 

PurgeandFire

zxcvmkgdfg
Reaction score
509
no, :
Code:
Random_Number=R2I(GetRandomReal(1.00, 3.00))
This line did a random number between 1.00 - 3.00, then converts it to integer with floor (1.99 -> 1, 2.01 -> 2); then converts it back to real (if it is 2, then converted to something between 1.999###... - 2.000...##...)

Oh. I missed the R2I (Real to Integer) part. I thought it was simply:

JASS:
Random_Number = GetRandomReal(1.00,3.00)


My mistake. :p
 

Duwenbasden

Ver 6 CREATE energy AS SELECT * FROM u.energy
Reaction score
165
> As soon as it is type Real == any number type, it will never work.
You sure?
JASS:
function realtest takes nothing returns nothing
    local real test = 50.2
    if test == 50.2 then
        call BJDebugMsg("1")
    endif
endfunction

Displays 1 on screen after you call it.

http://en.wikipedia.org/wiki/Floating_point#Accuracy_problems
# Equality is problematical! Two computational sequences that are mathematically equal may well produce different floating-point values. Programmers often perform comparisons within some tolerance (often a decimal constant, itself not accurately represented), but that doesn't necessarily make the problem go away.

My solution is to avoid comparing equality between reals as they can be problematic.
 

Ninja_sheep

Heavy is credit to team!
Reaction score
64
It's really annoying -.-
If i remove the 'else' my WE crashes...

But the integer i got now :)

JASS:

function Trig_Assigment_Conditions takes nothing returns boolean
    if ( not ( IsUnitType(GetTriggerUnit(), UNIT_TYPE_HERO) == true ) ) then
        return false
    endif
    return true
endfunction


function Trig_Assigment_Actions takes nothing returns nothing
    local unit TriggUnit = GetTriggerUnit()
    local player TriggPlayer = GetOwningPlayer(udg_TriggUnit)
    local integer TriggPlayer_Wood = GetPlayerState(udg_TriggPlayer, PLAYER_STATE_RESOURCE_LUMBER)
    local integer TriggPlayer_Gold = GetPlayerState(udg_TriggPlayer, PLAYER_STATE_RESOURCE_GOLD)
    local real TriggUnit_MaxLife = GetUnitStateSwap(UNIT_STATE_MAX_LIFE, udg_TriggUnit)
    local real TriggUnit_MaxMana = GetUnitStateSwap(UNIT_STATE_MAX_MANA, udg_TriggUnit)
    local integer HeroAgi
    local integer HeroStr
    local integer HeroInt
    local integer Random_Number
    call SetPlayerState( TriggPlayer, PLAYER_STATE_RESOURCE_GOLD, TriggPlayer_Gold +  R2I(TriggUnit_MaxLife))
    call SetPlayerState( TriggPlayer, PLAYER_STATE_RESOURCE_LUMBER, TriggPlayer_Wood +  R2I(TriggUnit_MaxMana))
    call SetUnitState( TriggUnit, UNIT_STATE_LIFE, TriggUnit_MaxLife)
    call SetUnitState( TriggUnit, UNIT_STATE_MANA, TriggUnit_MaxMana)
    
    set Random_Number=GetRandomInt(1, 3)
    
// (>^.^>) (>^.^>) (>^.^>) (>^.^>) (>^.^>) (>^.^<) (<^.^<)(<^.^<) (<^.^<) (<^.^<) (<^.^<)    
//                             Till here the trigger is done.
//                              Come on! It's allmost done!
// (>^.^>) (>^.^>) (>^.^>) (>^.^>) (>^.^>) (>^.^<) (<^.^<)(<^.^<) (<^.^<) (<^.^<) (<^.^<)    



    if Random_Number==1.0 then
        set HeroAgi = GetHeroAgi(TriggUnit, false)
        call SetHeroAgi( TriggUnit, (HeroAgi + 1) )
     else
    endif

    if Random_Number==2.0 then
        set HeroStr = GetHeroStr(TriggUnit, false)
        call SetHeroStr( TriggUnit, (HeroStr + 1) )
     else
    endif

    if Random_Number==3.0 then
        set HeroInt = GetHeroInt(TriggUnit, false)
        call SetHeroStr( TriggUnit, (HeroInt + 1))
    else
    endif
endfunction

//===========================================================================
function InitTrig_Assigment_Kopieren takes nothing returns nothing
    set gg_trg_Assigment_Kopieren = CreateTrigger(  )
    call TriggerAddCondition( gg_trg_Assigment_Kopieren, Condition( function Trig_Assigment_Conditions ) )
    call TriggerAddAction( gg_trg_Assigment_Kopieren, function Trig_Assigment_Actions )
endfunction
 

Duwenbasden

Ver 6 CREATE energy AS SELECT * FROM u.energy
Reaction score
165
still comparing reals:

JASS:
    if Random_Number==1 then      // dropped the decimal -- compiler will think it is real
                                  // if you have a decimal point
        set HeroAgi = GetHeroAgi(TriggUnit, false)
        call SetHeroAgi( TriggUnit, (HeroAgi + 1) )
     elseif  Random_Number==2 then
        set HeroStr = GetHeroStr(TriggUnit, false)
        call SetHeroStr( TriggUnit, (HeroStr + 1) )
     elseif Random_Number==3 then
        set HeroInt = GetHeroInt(TriggUnit, false)
        call SetHeroStr( TriggUnit, (HeroInt + 1))
    else
        //nop
    endif
 

AceHart

Your Friendly Neighborhood Admin
Reaction score
1,495
> But the integer i got now

I still see decimals though: 1.0, 2.0 and 3.0...


JASS has an "elseif" too btw:

if <condition> then
...
elseif <other condition> then
...
else
...
endif
 

Ninja_sheep

Heavy is credit to team!
Reaction score
64
oO, strange. I removed the ".0" now. that worked.
but with the elseifs it crashed!

JASS:
function Trig_Assigment_Conditions takes nothing returns boolean
    if ( not ( IsUnitType(GetTriggerUnit(), UNIT_TYPE_HERO) == true ) ) then
        return false
    endif
    return true
endfunction


function Trig_Assigment_Actions takes nothing returns nothing
    local unit TriggUnit = GetTriggerUnit()
    local player TriggPlayer = GetOwningPlayer(udg_TriggUnit)
    local integer TriggPlayer_Wood = GetPlayerState(udg_TriggPlayer, PLAYER_STATE_RESOURCE_LUMBER)
    local integer TriggPlayer_Gold = GetPlayerState(udg_TriggPlayer, PLAYER_STATE_RESOURCE_GOLD)
    local real TriggUnit_MaxLife = GetUnitStateSwap(UNIT_STATE_MAX_LIFE, udg_TriggUnit)
    local real TriggUnit_MaxMana = GetUnitStateSwap(UNIT_STATE_MAX_MANA, udg_TriggUnit)
    local integer HeroAgi
    local integer HeroStr
    local integer HeroInt
    local integer Random_Number
    call SetPlayerState( TriggPlayer, PLAYER_STATE_RESOURCE_GOLD, TriggPlayer_Gold +  R2I(TriggUnit_MaxLife))
    call SetPlayerState( TriggPlayer, PLAYER_STATE_RESOURCE_LUMBER, TriggPlayer_Wood +  R2I(TriggUnit_MaxMana))
    call SetUnitState( TriggUnit, UNIT_STATE_LIFE, TriggUnit_MaxLife)
    call SetUnitState( TriggUnit, UNIT_STATE_MANA, TriggUnit_MaxMana)
    
    set Random_Number=GetRandomInt(1, 3)
    
// (&gt;^.^&gt;) (&gt;^.^&gt;) (&gt;^.^&gt;) (&gt;^.^&gt;) (&gt;^.^&gt;) (&gt;^.^&lt;) (&lt;^.^&lt;)(&lt;^.^&lt;) (&lt;^.^&lt;) (&lt;^.^&lt;) (&lt;^.^&lt;)    
//                             Till here the trigger is done.
//                              Come on! It&#039;s allmost done!
// (&gt;^.^&gt;) (&gt;^.^&gt;) (&gt;^.^&gt;) (&gt;^.^&gt;) (&gt;^.^&gt;) (&gt;^.^&lt;) (&lt;^.^&lt;)(&lt;^.^&lt;) (&lt;^.^&lt;) (&lt;^.^&lt;) (&lt;^.^&lt;)    



    if Random_Number==1 then
        set HeroAgi = GetHeroAgi(TriggUnit, false)
        call SetHeroAgi( TriggUnit, (HeroAgi + 1) )
    elseif Random_Number==2 then
        set HeroStr = GetHeroStr(TriggUnit, false)
        call SetHeroStr( TriggUnit, (HeroStr + 1) )
    elseif Random_Number==3 then
        set HeroInt = GetHeroInt(TriggUnit, false)
        call SetHeroStr( TriggUnit, (HeroInt + 1))
    endif
endfunction
 

PurgeandFire

zxcvmkgdfg
Reaction score
509
That is probably because you use the elseifs.

Persay:
A man named Bobo walks down the street and he meets a magician. The magician puts a red ball into one cup, a green into another, then a blue one into another cup as well. If Bobo chooses one cup, the chance it will be blue is 1/3.

So, if he picks blue, he will win 2 dollars. If he picks red, he will win 5 dollars. If he picks green, he will win 4 dollars.

Since he is only picking one, he cannot pick one and have all three balls. :p rofl

Basically, if you pick a random integer between 1 and 3, the chances getting all of them when only picking one is 0%.

So, what I think is that you should do this instead:
JASS:
    if Random_Number==1 then
        set HeroAgi = GetHeroAgi(TriggUnit, false)
        call SetHeroAgi( TriggUnit, (HeroAgi + 1) )
    endif
    if Random_Number==2 then
        set HeroStr = GetHeroStr(TriggUnit, false)
        call SetHeroStr( TriggUnit, (HeroStr + 1) )
    endif
    if Random_Number==3 then
        set HeroInt = GetHeroInt(TriggUnit, false)
        call SetHeroStr( TriggUnit, (HeroInt + 1))
    endif
endfunction


This is because they are each separate effects, so I think it got a syntax from that. ;)
 

Ninja_sheep

Heavy is credit to team!
Reaction score
64
okaaaaay, here's the smae problem i had before :(
If i use your trigger (remove the elses) = crash :(
thx anyway :(
 

Duwenbasden

Ver 6 CREATE energy AS SELECT * FROM u.energy
Reaction score
165
Code:
local player TriggPlayer = GetOwningPlayer(udg_TriggUnit)
local integer TriggPlayer_Wood = GetPlayerState(udg_TriggPlayer, PLAYER_STATE_RESOURCE_LUMBER)

who are udg_TriggUnit and udg_TriggPlayer?

PurgeandFire: That is a god awful waste of clock cycles. The trigger will compare with all three conditions, instead of 1-3 times when using elseifs. It isn't wrong, just really bad design.
 

PurgeandFire

zxcvmkgdfg
Reaction score
509
Woah, stupid me to make that mistake. I was thinking something weird at the moment, sorry. :p

@Ninja_Sheep: Remove the "udg_"s! They are not required because you are using locals not globals! lol :D XD
 

Duwenbasden

Ver 6 CREATE energy AS SELECT * FROM u.energy
Reaction score
165
Code:
local player TriggPlayer = GetOwningPlayer(udg_TriggUnit)
local integer TriggPlayer_Wood = GetPlayerState(udg_TriggPlayer, PLAYER_STATE_RESOURCE_LUMBER)

who are udg_TriggUnit and udg_TriggPlayer?
 
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

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top