[Andrewgosu's JASS Corner]

Status
Not open for further replies.

Andrewgosu

The Silent Pandaren Helper
Reaction score
716
Code:
    local boolexpr [B]struct[/B] = Condition( function ...() )
    local boolexpr [B]immune[/B] = Condition( function ...() )
    local boolexpr [B]enemy[/B] = Condition( function ..() )

Now, if I have those 3 boolean expressions, how can I use them in one functions, like the following.

Code:
call GroupEnumUnitsInRange( g, x, y, 300, [B]struct, immune, enemy[/B] )

Can I do that?
 

phyrex1an

Staff Member and irregular helper
Reaction score
447
Or, if you for some reason is unable to make a new function, use the native And(<boolexpr>,<boolexpr>) to concat the boolexps.
Just remember that you still have to clean the leaks from the original expressions.

However, in most cases what ace says is a much better solution.
 

Andrewgosu

The Silent Pandaren Helper
Reaction score
716
How much slower is:

Code:
function a takes nothing returns boolean
    return (A)
endfunction

function b takes nothing returns boolean
    return (B)
endfunction

function c takes nothing returns boolean
    return (C)
endfunction

function d takes nothing returns boolean
    return a() and b() and c()
endfunction

from:

Code:
function x takes nothing returns boolean
    return (A) and (B) and (C)
endfunction

I am asking this because, if I squeeze the conditions into 1 function with "and's", it would decrease readability alot.
 

Andrewgosu

The Silent Pandaren Helper
Reaction score
716
I know that. I need to use a boolean expression inside a unit group function,
not with an if/then/else. I was asking, is it worth to make 4 functions and
have a really good overview and readability or use 1 function for maximal
functionality, but have a poor readability.
 

Chocobo

White-Flower
Reaction score
409
I know that. I need to use a boolean expression inside a unit group function,
not with an if/then/else. I was asking, is it worth to make 4 functions and
have a really good overview and readability or use 1 function for maximal
functionality, but have a poor readability.

Readability.
 

SFilip

Gone but not forgotten
Reaction score
634
> How much slower is
Not much...well sort of.
Presumably just about the same as the difference between calling 3 BJs and 3 natives.
And considering the fact that around 3/4 of the maps out there are made with GUI (99% BJs) and no one ever complained about it...well you get the idea...

Yet unless you have a very good why not to...keep it all in the same function.
Need readability?
Code:
function x takes nothing returns boolean
    local boolean condition1 = (.....)
    local boolean condition2 = (.....)
    local boolean condition3 = (.....)
    return condition1 and condition2 and condition3
endfunction
 

Andrewgosu

The Silent Pandaren Helper
Reaction score
716
Code:
function x takes nothing returns boolean
    local boolean condition1 = (.....)
    local boolean condition2 = (.....)
    local boolean condition3 = (.....)
    return condition1 and condition2 and condition3
endfunction

That is basically the same example I gave.

I was talking about using multiple boolean expressions in unit group functions, but anyway, I get the idea.
Readability it will be, then.
 

Andrewgosu

The Silent Pandaren Helper
Reaction score
716
Code:
constant function RevivalTime takes nothing returns real
    return 10.0
endfunction 

constant function RevivalArt takes nothing returns boolean
    return true
endfunction

[B]constant function GetPlayerColourId takes playercolor r returns string
	if     r == PLAYER_COLOR_RED then
		return "|ccfff0202"
	elseif r == PLAYER_COLOR_BLUE then
		return "|ccf0041ff"
	elseif r == PLAYER_COLOR_CYAN then
		return "|ccf1be5b8"
	elseif r == PLAYER_COLOR_PURPLE then
		return "|ccf530080"
	elseif r == PLAYER_COLOR_YELLOW then
		return "|ccffffc00"
	elseif r == PLAYER_COLOR_ORANGE then
		return "|ccffe890d"
	elseif r == PLAYER_COLOR_GREEN then
		return "|ccf1fbf00"
	elseif r == PLAYER_COLOR_PINK then
		return "|ccfe45aaf"
	elseif r == PLAYER_COLOR_LIGHT_GRAY then
		return "|ccf949596"
	elseif r == PLAYER_COLOR_LIGHT_BLUE then
		return "|ccf7dbef1"
	elseif r == PLAYER_COLOR_AQUA then
		return "|ccf0f6145"
	elseif r == PLAYER_COLOR_BROWN then
		return "|ccf4d2903"
	endif
	return "|cffffcc00"
endfunction              [/B]

function Trig_Hero_Dies_Conditions takes nothing returns boolean
    return (IsUnitType(GetTriggerUnit(), UNIT_TYPE_HERO) == true)
endfunction 

function Trig_Hero_Dies_Actions takes nothing returns nothing
    local timer       t = CreateTimer()
    local timerdialog d = CreateTimerDialog(t)
    local unit        a = GetTriggerUnit()
    local player      p = GetOwningPlayer(a)
    local real        x = GetPlayerStartLocationX(p)
    local real        y = GetPlayerStartLocationY(p)
[B]    local playercolor r = GetPlayerColor(p)[/B]
[COLOR="Red"]    local string      s = GetPlayerColourid() + GetPlayerName(p) + "|r"[/COLOR]
    
    call TimerDialogSetTitle( d, s )
    call TimerDialogDisplay( d, true )    
    call TimerStart( t, RevivalTime(), false, null )
    call TriggerSleepAction( RevivalTime() )
    call ReviveHero( a, x, y, RevivalArt() )
    call DestroyTimerDialog(d)
    call DestroyTimer(t)
    
    set t = null
    set d = null
    set a = null
    set p = null
    set r = null
endfunction

//===========================================================================
function InitTrig_Hero_Dies takes nothing returns nothing
    set gg_trg_Hero_Dies = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Hero_Dies, EVENT_PLAYER_UNIT_DEATH )
    call TriggerAddCondition( gg_trg_Hero_Dies, Condition( function Trig_Hero_Dies_Conditions ) )
    call TriggerAddAction( gg_trg_Hero_Dies, function Trig_Hero_Dies_Actions )
endfunction

It says "Expected a name". Can anyone tell me, what I am doing wrong?
 

Andrewgosu

The Silent Pandaren Helper
Reaction score
716
Just before reading your post I noticed that the "i" should be "I". But, still. Now it says "Invalid number of arguments" at the same line.
 

emjlr3

Change can be a good thing
Reaction score
395
but then you would be like a dog following his masters orders, your not a dog are you?

the point of help is not to do it for you, its to help you understand your mistake, so you do not make it again
 

Andrewgosu

The Silent Pandaren Helper
Reaction score
716
Code:
function FloatingTextBase takes unit a, string s returns nothing
    local texttag t = CreateTextTag()
    
    call SetTextTagText( t, s, 10.0 )
    call SetTextTagPos( t, GetUnitX(a), GetUnitY(a), 0.00 )
    call SetTextTagColor( t, 255, 255, 255, [B]100[/B] )    
    call SetTextTagPermanent( t, false )
    call SetTextTagVelocity( t, 64, 90 )
    call SetTextTagLifespan( t, 5 )
    call SetTextTagFadepoint( t, 4 )
        
    set t = null
endfunction

This function should create a floating text, at the position of a given unit, showing a specified string.

I use this trigger to call it, but the floating text is never shown. Used a debug message, too, and it was displayed...

I think I am messing up with the alpha value of the floating text.

Code:
function Trig_Cast_Spell_Actions takes nothing returns nothing   
    call FloatingTextBase( GetTriggerUnit(), GetAbilityName(GetSpellAbilityId()) )
endfunction

//===========================================================================
function InitTrig_Cast_Spell takes nothing returns nothing
    set gg_trg_Cast_Spell = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Cast_Spell, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddAction( gg_trg_Cast_Spell, function Trig_Cast_Spell_Actions )
endfunction
 

SFilip

Gone but not forgotten
Reaction score
634
Alpha should be expressed with a number from 0 to 255 as well. Try 255 instead of 100.
Also try SetTextTagVisibility(t, true).
 
Status
Not open for further replies.
General chit-chat
Help Users
  • No one is chatting at the moment.

      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