• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[JASS] Converting GUI

Status
Not open for further replies.

ABM

ABM

Level 7
Joined
Jul 13, 2005
Messages
279
Hi everyone,
i am new to Jass and still have problem going from the mess GUI is doing to trigger, to the nice orderly struct of VJass.
i have Converted some GUI trigger to Jass and i simplified a bit the name but the struct is all disassembled in many trigger...
i am not sure on how to make it into a nice compact and readable efficient Jass.

(the start trigger can be replaced by a custom text in GUI "call nameoffunction" i think, this one should be easy)
[Jass=Start]
function Trig_Start_Actions takes nothing returns nothing
call ConditionalTriggerExecute( gg_trg_PickUpTree )
endfunction

//===========================================================================
function InitTrig_Start takes nothing returns nothing
set gg_trg_Start = CreateTrigger( )
call TriggerAddAction( gg_trg_Start, function Trig_Start_Actions )
endfunction[/code]


(the trigger is picking all destructible at map ini and check if picked destructible is the correct type, then it add the destructible to the next trigger event "destructible die")
because in GUI the event destructible die need a specifique destructible and not a destructible type.
[Jass=PickUpTree]
function Trig_PickUpTree_003 takes nothing returns boolean
if ( ( GetDestructableTypeId(GetEnumDestructable()) == 'NTtw' ) ) then
return true
endif
if ( ( GetDestructableTypeId(GetEnumDestructable()) == 'B002' ) ) then
return true
endif
if ( ( GetDestructableTypeId(GetEnumDestructable()) == 'B001' ) ) then
return true
endif
if ( ( GetDestructableTypeId(GetEnumDestructable()) == 'B003' ) ) then
return true
endif
if ( ( GetDestructableTypeId(GetEnumDestructable()) == 'B004' ) ) then
return true
endif
if ( ( GetDestructableTypeId(GetEnumDestructable()) == 'ZTtw' ) ) then
return true
endif
if ( ( GetDestructableTypeId(GetEnumDestructable()) == 'FTtw' ) ) then
return true
endif
if ( ( GetDestructableTypeId(GetEnumDestructable()) == 'BTtw' ) ) then
return true
endif
if ( ( GetDestructableTypeId(GetEnumDestructable()) == 'ATtr' ) ) then
return true
endif
return false
endfunction

function Trig_PickUpTree_002 takes nothing returns boolean
if ( not Trig_PickUpTree_003() ) then
return false
endif
return true
endfunction

function Trig_PickUpTree_001 takes nothing returns nothing
if ( Trig_PickUpTree_002() ) then
call TriggerRegisterDeathEvent( gg_trg_TreeDropWood, GetEnumDestructable() )
else
endif
endfunction

function Trig_PickUpTree_Actions takes nothing returns nothing
call EnumDestructablesInRectAll( GetPlayableMapRect(), function Trig_PickUpTree_001 )
endfunction

//===========================================================================
function InitTrig_PickUpTree takes nothing returns nothing
set gg_trg_PickUpTree = CreateTrigger( )
call TriggerAddAction( gg_trg_PickUpTree, function Trig_PickUpTree_Actions )
endfunction[/code]


(then, the second trigger check the type of the added dying destructible and give an item upon death of destructible depending of type of destructible)
[Jass=TreeDropWood]
function Trig_TreeDropWood_004 takes nothing returns boolean
if ( ( GetDestructableTypeId(GetDyingDestructable()) == 'ZTtw' ) ) then
return true
endif
if ( ( GetDestructableTypeId(GetDyingDestructable()) == 'FTtw' ) ) then
return true
endif
if ( ( GetDestructableTypeId(GetDyingDestructable()) == 'BTtw' ) ) then
return true
endif
if ( ( GetDestructableTypeId(GetDyingDestructable()) == 'ATtr' ) ) then
return true
endif
return false
endfunction

function Trig_TreeDropWood_005 takes nothing returns boolean
if ( ( GetDestructableTypeId(GetDyingDestructable()) == 'B002' ) ) then
return true
endif
if ( ( GetDestructableTypeId(GetDyingDestructable()) == 'B001' ) ) then
return true
endif
if ( ( GetDestructableTypeId(GetDyingDestructable()) == 'B003' ) ) then
return true
endif
if ( ( GetDestructableTypeId(GetDyingDestructable()) == 'B004' ) ) then
return true
endif
return false
endfunction

function Trig_TreeDropWood_003 takes nothing returns boolean
if ( not Trig_TreeDropWood_005() ) then
return false
endif
return true
endfunction

function Trig_TreeDropWood_002 takes nothing returns boolean
if ( not ( GetDestructableTypeId(GetDyingDestructable()) == 'NTtw' ) ) then
return false
endif
return true
endfunction

function Trig_TreeDropWood_001 takes nothing returns boolean
if ( not Trig_TreeDropWood_004() ) then
return false
endif
return true
endfunction

function Trig_TreeDropWood_Actions takes nothing returns nothing
set integer S = ( S + 1 )
if ( Trig_TreeDropWood_001() ) then
set udg_DeadTree[udg_S] = GetDyingDestructable()
set udg_Loc = GetDestructableLoc(GetDyingDestructable())
call CreateItemLoc( 'I011', udg_Loc )
call SetItemUserData( GetLastCreatedItem(), 99 )
call RemoveLocation(udg_Loc)
call RemoveDestructable( udg_DeadTree[udg_S] )
else
if ( Trig_TreeDropWood_002() ) then
set udg_DeadTree[udg_S] = GetDyingDestructable()
set udg_Loc = GetDestructableLoc(GetDyingDestructable())
call CreateItemLoc( 'I06A', udg_Loc )
call SetItemUserData( GetLastCreatedItem(), 99 )
call RemoveLocation(udg_Loc)
call RemoveDestructable( udg_DeadTree[udg_S] )
else
if ( Trig_TreeDropWood_003() ) then
set udg_DeadTree[udg_S] = GetDyingDestructable()
set udg_Loc = GetDestructableLoc(GetDyingDestructable())
call CreateItemLoc( 'I012', udg_Loc )
call SetItemUserData( GetLastCreatedItem(), 99 )
call RemoveLocation(udg_Loc)
call RemoveDestructable( udg_DeadTree[udg_S] )
else
endif
endif
endif
call EnableTrigger( GetTriggeringTrigger() )
endfunction

//===========================================================================
function InitTrig_TreeDropWood takes nothing returns nothing
set gg_trg_TreeDropWood = CreateTrigger( )
call TriggerAddAction( gg_trg_TreeDropWood, function Trig_TreeDropWood_Actions )
endfunction[/code]

Should i use 2 triggers or is it possible to merge it, also about the call what should i write exactly. the GUI use globals, but maybe it would be better to use local, make the code simplier..?

thanks for your time and help ^^
 
Level 28
Joined
Jan 26, 2007
Messages
4,789
In JASS, you've got something called 'elseif'.
JASS:
if GetDestructableTypeId(...) == 'what' then
    // Do stuff
elseif GetDestructableId(...) == 'ohay' then
    // Do other stuff
endif

You also never use locations! If you ever see something with "Loc" in its name, immediately change that so it works with coordinates.

Another thing is that most people don't work with actions, they use conditions and return false.

Also, your event is in a weird place. The second trigger doesn't even have an event?

Last but not least: you've got way too many automatically created functions.
Most (all?) of them or conditions, you should place conditions in the IF-statement, not in another function.

JASS:
    // Wrong (kind-of):
function Cond0052415fg1x5yh1s3fx5y1hc5 takes nothing returns boolean
    if ( not ( SomethingIsTrue ) == true ) then
        return true
    endif
    return false
endfunction

function DoSomething takes nothing returns nothing
    if Cond0052415fg1x5yh1s3fx5y1hc5() then
        // Hello
    endif
endfunction


    // Better:
function DoSomething takes nothing returns nothing
    if not SomethingIsTrue then
        // Hello
    endif
endfunction


    // If you really need a separate condition (because you need it a lot for example):
function awesomeCondition takes nothing returns boolean
    return SomethingIsTrue == false
endfunction

function DoSomething takes nothing returns nothing
    if awesomeCondition() then
        // Hello
    endif
endfunction



Clean up the code, then we shall have a look at it :)
 

ABM

ABM

Level 7
Joined
Jul 13, 2005
Messages
279
Well actually my problem is cleaning the code...
what i writted is the GUI code converted into Jass... wich is a real mess
so i am trying to understand how to clean it to make it look like real Jass code.

well i will try to figure out how to merge all the crazy trigger the GUI converter make and make it more compact and understandable.

the first trigger is the trigger wich will launch the real trigger.
the real trigger is
2nd pickup: the one wich select the tree and add them to the 3rd trigger event
3rd dropitem: wich check the added destructible on death and drop item following condition.
 
Level 28
Joined
Jan 26, 2007
Messages
4,789
Well, I've already given you information on how to clean it.
Perhaps you can apply those things I've said, then show the new code and we'll see what can still be improved.
It's a really messy code, so I didn't expect it to be cleaned in a single post (and I also want you to clean the code yourself :D).
 

ABM

ABM

Level 7
Joined
Jul 13, 2005
Messages
279
ok i worked hard and looked for similar library/system/snippet,
i merged everything according to other struct....
the code is much cleaner and nicer but it is not working yet, not even sure if what i am coding make sens :p

[Jass=library]
library TREEDROP initializer Init
globals
integer i
location loc
destructable tree
endglobals

private function IsTree takes nothing returns boolean
local integer T = GetDestructableTypeId(GetFilterDestructable())
set destructable tree = GetDyingDestructable()
call DisplayTimedTextToForce( GetForceOfPlayer(Player(0)), 10.00, GetDestructableName(tree) )
call DisplayTimedTextToForce( GetForceOfPlayer(Player(0)), 10.00, ( "Location of dying tree is " + ( I2S(T))))
set loc = GetDestructableLoc(tree)
//OtherTrees
if T == 'ZTtw' or T == 'BTtw' or T == 'FTtw' or T =='ATtr' then
set i = 'I011' //Wood
return true
//Bush
elseif T == 'B001' or T == 'B002' or T == 'B003' or T =='B004' then
set i = 'I012' //Tinder
return true
//Deadtree
elseif T == 'NTtw' then
set i = 'I06A' //PetrifiedWood
return true
endif
call RemoveLocation(loc)
set tree = null
return false
endfunction

private function DropTree takes nothing returns nothing
call DisplayTimedTextToForce( GetForceOfPlayer(Player(0)), 10.00, ( "the item name is " + I2S(i) ) )
call CreateItemLoc( i, loc )
call SetItemUserData( GetLastCreatedItem(), 99 )
call RemoveLocation(loc)
call RemoveDestructable(tree)
set tree = null
endfunction

private function Register takes nothing returns nothing
call TriggerRegisterDeathEvent(bj_destInRegionDiesTrig, GetEnumDestructable())
endfunction

private function Init takes nothing returns nothing
set bj_destInRegionDiesTrig = CreateTrigger()
call EnumDestructablesInRect(bj_mapInitialPlayableArea, Condition(function IsTree), function Register)
call TriggerAddAction(bj_destInRegionDiesTrig, function DropTree)
endfunction
endlibrary[/code]

right now i have a warning with the variable tree
//Line 860: Syntax error, unexpected "tree"?

can i get a little help? !-.-
 
Level 28
Joined
Jan 26, 2007
Messages
4,789
I don't know where line 860 is in your code (it's best if you mention that too), but the error is probably in set destructable tree = ..., remove the "destructable" there.
It's looking better so far.

Now we're going to get rid of some leaks (force leaks), locations and BJ's.

First: the leaks (this also removes some BJ's actually).
Change DisplayTimedTextToForce( GetForceOfPlayer(Player(0)), 10.00, GetDestructableName(tree) ) to DisplayTextToPlayer( Player(0), 0., 0., text ).
It's probably just for debugging, but if you're gonna debug, you either use the above or call BJDebugMsg( text ).
Your method is longer and it leaks.

Now let's change the locations (this also removes some BJ's)
Create 2 private real variables: x and y.
JASS:
globals
    private real x
    private real y
endglobals

Then you can do something like this:
JASS:
set x = GetDestructableX( dest )
set y = GetDestructableY( dest )

To create an item, use call CreateItem( 'item', x, y )


Now the last 2 BJ's that are left:
Change GetDyingDestructable with GetTriggerWidget()
Change GetLastCreatedItem() with bj_lastCreatedItem


Change these things, then we'll evaluate the code again :).
 

ABM

ABM

Level 7
Joined
Jul 13, 2005
Messages
279
[Jass=Code]
library TREEDROP initializer Init
globals
integer i
private real x
private real y
destructable tree
endglobals

private function IsTree takes nothing returns boolean
local integer T = GetDestructableTypeId(GetFilterDestructable())
set tree = GetTriggerWidget()
call DisplayTextToPlayer(Player(0), 0.,0., GetDestructableName(tree) )
call DisplayTextToPlayer(Player(0), 0.,0., "Location of dying tree is " + ( I2S(T)))
set x = GetDestructableX(tree)
set y = GetDestructableY(tree)
//OtherTrees
if T == 'ZTtw' or T == 'BTtw' or T == 'FTtw' or T =='ATtr' then
set i = 'I011' //Wood
return true
//Bush
elseif T == 'B001' or T == 'B002' or T == 'B003' or T =='B004' then
set i = 'I012' //Tinder
return true
//Deadtree
elseif T == 'NTtw' then
set i = 'I06A' //PetrifiedWood
return true
endif
set tree = null
return false
endfunction

private function DropTree takes nothing returns nothing
call DisplayTextToPlayer(Player(0), 0.,0., "the item name is " + I2S(i) )
call CreateItem( i, x, y )
call SetItemUserData( bj_lastCreatedItem(), 99 )
call RemoveDestructable(tree)
set tree = null
endfunction

private function Register takes nothing returns nothing
call TriggerRegisterDeathEvent(bj_destInRegionDiesTrig, GetEnumDestructable())
endfunction

private function Init takes nothing returns nothing
set bj_destInRegionDiesTrig = CreateTrigger()
call EnumDestructablesInRect(bj_mapInitialPlayableArea, Condition(function IsTree), function Register)
call TriggerAddAction(bj_destInRegionDiesTrig, function DropTree)
endfunction
endlibrary[/code]

Change GetDyingDestructable with GetTriggerWidget()
Change GetLastCreatedItem() with bj_lastCreatedItem

Both these things make error when saving:
cannot convert widget to destructable
undeclared function bj_lastCreatedItem

but strangely Jassnewgen recognize these words....(but they make error in the code)

is there a way in Jass to make that a destructible drop an item upon death (filtering destructible, and droping item)

or should i use the GUI way (with jass trigger)
pick every destructible in map, filter destructible, add destructible to 2nd trigger event "this destructible die"
second trigger store destructible upon death and drop item upon filtering
 
Last edited:
Level 28
Joined
Jan 26, 2007
Messages
4,789
I will just note this: JASS can do everything that GUI can do, and better while there are many things that GUI cannot do that JASS can.
This is because GUI is just a graphical user interface (hence the name) of JASS. So it's JASS, but with buttons.

bj_lastCreatedItem isn't a function, it's a variable. Just like bj_lastCreatedUnit and bj_FORCE_ALL_PLAYERS (and others).
So don't use the brackets, it's just call SetItemUserData( bj_lastCreatedItem, 99 )

The GetDyingDestructable-thing is weird because of this:
JASS:
function GetDyingDestructable takes nothing returns destructable
    return GetTriggerWidget()
endfunction
As you can see, the BJ function "GetDyingDestructable" returns a destructable. To do that, it returns "GetTriggerWidget()". So GetTriggerWidget() must be a destructable, otherwise the BJ would be wrong (which it isn't).
Pretty confusing, but you can use GetDyingDestructable then.

It is also recommended to make all other variables (i and tree) private as well.


Now that it looks rather clean, let's change it so it actually works (I don't believe it does right now, but I may be wrong :p).
EnumDestructablesInRect's condition should probably be null.
If you have a lot of other destructables in the map, you can create an ITE (If-Then-Else) within the Register-function itself so you only register the ones you need.
JASS:
private function Register takes nothing returns nothing
    local integer id = GetDestructableTypeId(GetFilterDestructable())
        
    if id == 'ZTtw' or id == 'BTtw' or id == 'FTtw' or id =='ATtr' or id == 'B001' or id == 'B002' or id == 'B003' or id =='B004' or id == 'NTtw' then
        call TriggerRegisterDeathEvent(bj_destInRegionDiesTrig, GetEnumDestructable())
    endif
endfunction

Instead of an action, you can do call TriggerAddCondition( bj_destInRegionDiesTrig, Condition( function DropTree ) )
Then the DropTree-function would always return false and can be merged with the IsTree-function
JASS:
private function DropTree takes nothing returns boolean
    local integer T = GetDestructableTypeId(GetDyingDestructable())
    set tree = GetDyingDestructable()
    set x = GetDestructableX(tree)
    set y = GetDestructableY(tree)
    
    //OtherTrees
    if T == 'ZTtw' or T == 'BTtw' or T == 'FTtw' or T =='ATtr' then
    set i = 'I011'  //Wood
    //Bush
    elseif T == 'B001' or T == 'B002' or T == 'B003' or T =='B004' then
    set i = 'I012'  //Tinder
    //Deadtree   
    elseif T == 'NTtw' then  
    set i = 'I06A'  //PetrifiedWood
    endif
    
    call DisplayTextToPlayer(Player(0), 0.,0., "the item name is " + I2S(i) )
    call CreateItem( i, x, y )  
    call SetItemUserData( bj_lastCreatedItem, 99 )
    call RemoveDestructable(tree)
    set tree = null
    
    return false
endfunction
 
Level 19
Joined
Aug 8, 2007
Messages
2,765
JASS:
    call CreateItem( i, x, y )  
    call SetItemUserData( bj_lastCreatedItem, 99 )

this wont work. heres the GUI function

JASS:
function CreateItemLoc takes integer itemId, location loc returns item
    set bj_lastCreatedItem = CreateItem(itemId, GetLocationX(loc), GetLocationY(loc))
    return bj_lastCreatedItem
endfunction

CreateItem wont set bj_LastCreatedItem

instead change it to this

JASS:
    call SetItemUserData( CreateItem( i, x, y ), 99 )

also, If im reading your code correctly, it wil only create the item for the last enum'd tree in the Enum because each enum sets i = 'item'
 

ABM

ABM

Level 7
Joined
Jul 13, 2005
Messages
279
Thanks Arhowk i modified the SetItemUserData ^^
only for last tree?? actually i need for all tree, do i need to store all tree into a variable? i need that when tree die it check and then spawn the correct item...


>>it wil only create the item for the last enum'd tree in the Enum because each enum sets i = 'item'
actually i don't completly understand that sentence, do you mean it loop through all tree and override each tree each time, so the value wich stay is the last one?
so how can i change that?


Thanks ap0calypse
Hum the trigger look nice but it doesn't work :(


at start of game (map ini) the trigger run at least 2 times
because it write all the message twice

but then when a tree die nothing happen not even the message
before the item wouldn't appear but the message was there on tree death

[Jass=]
library TREEDROP initializer Init
globals
private integer i
private real x
private real y
private destructable tree
endglobals

private function DropTree takes nothing returns boolean
local integer T = GetDestructableTypeId(GetFilterDestructable())
set tree = GetDyingDestructable()
call DisplayTextToPlayer(Player(0), 0.,0., GetDestructableName(tree) )
set x = GetDestructableX(tree)
set y = GetDestructableY(tree)
call DisplayTextToPlayer(Player(0), 0.,0., "Location of dying tree is " + ( R2S(x)) + ( R2S(y)))
//OtherTrees
if T == 'ZTtw' or T == 'BTtw' or T == 'FTtw' or T =='ATtr' then
set i = 'I011' //Wood
//Bush
elseif T == 'B001' or T == 'B002' or T == 'B003' or T =='B004' then
set i = 'I012' //Tinder
//Deadtree
elseif T == 'NTtw' then
set i = 'I06A' //PetrifiedWood
endif
call DisplayTextToPlayer(Player(0), 0.,0., "the item name is " + I2S(i) )
call SetItemUserData( CreateItem( i, x, y ), 99 )
call RemoveDestructable(tree)
set tree = null
return false
endfunction

private function Register takes nothing returns nothing
local integer id = GetDestructableTypeId(GetFilterDestructable())
if id == 'ZTtw' or id == 'BTtw' or id == 'FTtw' or id =='ATtr' or id == 'B001' or id == 'B002' or id == 'B003' or id =='B004' or id == 'NTtw' then
call TriggerRegisterDeathEvent(bj_destInRegionDiesTrig, GetEnumDestructable())
endif
endfunction

private function Init takes nothing returns nothing
set bj_destInRegionDiesTrig = CreateTrigger()
call TriggerAddCondition( bj_destInRegionDiesTrig, Condition( function DropTree ) )
call EnumDestructablesInRect(bj_mapInitialPlayableArea, Condition(function DropTree), function Register)

endfunction
endlibrary[/code]

why does the trigger run when i didn't kill a tree yet at map start?
is there a problem with using the librabry code?
because right now it is the only trigger i have for the map (except the mapini to get vision)

i don't actually understand how the trigger is launching itself


EDIT
yeah it work !!! well almost...
i did change: call EnumDestructablesInRect(bj_mapInitialPlayableArea, Condition(function DropTree), function Register)
to : call EnumDestructablesInRect(bj_mapInitialPlayableArea, null, function Register)

so now the trigger don't run at start, but only when i kill a tree
but it doesn't create an item, i am afraid that integer i isn't working,
is it ok to store an item id into an integer?, because when i display the text(i) it make a weird number like 1243256415
i know id are ascii number but would the editor recognize 1243256415 as 'I011' or should i use string to store the id?

also the message create item is xxx doesn't even display

EDIT
i tried to move i to local in IsTree function, local T and under local i
the map crash when i cut a tree !-.-
omg... evil evil Jasss
 
Last edited:

ABM

ABM

Level 7
Joined
Jul 13, 2005
Messages
279
[trigger=]
pickuptree
Evénements
Temps - Elapsed game time is 1.00 seconds
Conditions
Actions
Destructible - Pick every destructible in (Playable map area) and do (Actions)
Boucle - Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Si - Conditions
Or - Any (Conditions) are true
Conditions
(Destructible-type of (Picked destructible)) Egal Ã* Mur d'arbres de Northrend
(Destructible-type of (Picked destructible)) Egal Ã* Mur d'arbres d'Ashenvale
(Destructible-type of (Picked destructible)) Egal Ã* Mur d'arbres de Barrens
(Destructible-type of (Picked destructible)) Egal Ã* Mur d'arbres en ruines
(Destructible-type of (Picked destructible)) Egal Ã* Mur d'arbre automne
(Destructible-type of (Picked destructible)) Egal Ã* Thorny Vines
(Destructible-type of (Picked destructible)) Egal Ã* Bushes (1)
(Destructible-type of (Picked destructible)) Egal Ã* Bushes (2)
(Destructible-type of (Picked destructible)) Egal Ã* Bushes (3)
Alors - Actions
Déclencheur - Add to DropTree <gen> the event (Destructible - (Picked destructible) dies)
Sinon - Actions[/trigger]

[trigger=]
DropTree
Evénements
Conditions
Actions
Set tree = (Dying destructible)
Set Loc = (Position of tree)
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Si - Conditions
Or - Any (Conditions) are true
Conditions
(Destructible-type of (Dying destructible)) Egal Ã* Mur d'arbres d'Ashenvale
(Destructible-type of (Dying destructible)) Egal Ã* Mur d'arbres de Barrens
(Destructible-type of (Dying destructible)) Egal Ã* Mur d'arbres en ruines
(Destructible-type of (Dying destructible)) Egal Ã* Mur d'arbre automne
Alors - Actions
Objet - Create |c00804000Wood|r at Loc
Objet - Set the custom value of (Last created item) to 99
Custom script: call RemoveLocation(udg_Loc)
Destructible - Remove tree
Sinon - Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Si - Conditions
Or - Any (Conditions) are true
Conditions
(Destructible-type of (Dying destructible)) Egal Ã* Bushes (1)
(Destructible-type of (Dying destructible)) Egal Ã* Bushes (2)
(Destructible-type of (Dying destructible)) Egal Ã* Bushes (3)
(Destructible-type of (Dying destructible)) Egal Ã* Thorny Vines
Alors - Actions
Objet - Create |c0000c400Tinder|r at Loc
Objet - Set the custom value of (Last created item) to 99
Custom script: call RemoveLocation(udg_Loc)
Destructible - Remove tree
Sinon - Actions
Objet - Create |c00804000Petrified Wood|r at Loc
Objet - Set the custom value of (Last created item) to 99
Custom script: call RemoveLocation(udg_Loc)
Destructible - Remove tree[/trigger]

The GUI version takes 2 trigger and works perfectly (tree in map 4600)
not only it works fine and is easily configurable but i can very easily add any tree created later to the system.

i think i will give up the Jass version trigger, because it is too complicated.
for other trigger Jass might be better but for this one GUI is easier.

if you can make this work in Jass and if it really is better (faster or less leak, and crashfree) i am interested if not i will stick to GUI this time.

Thanks Arhowk and ap0calypse for your help, i learned a few things in Jass thanks to you.
^^
 
Level 28
Joined
Jan 26, 2007
Messages
4,789
Arhowk said:
CreateItem wont set bj_LastCreatedItem
Completely forgot that bj_lastCreatedItem wouldn't work, thanks :D.

i did change: call EnumDestructablesInRect(bj_mapInitialPlayableArea, Condition(function DropTree), function Register)
to : call EnumDestructablesInRect(bj_mapInitialPlayableArea, null, function Register)

Indeed...
ap0calypse said:
EnumDestructablesInRect's condition should probably be null.
:D

is it ok to store an item id into an integer?, because when i display the text(i) it make a weird number like 1243256415
i know id are ascii number but would the editor recognize 1243256415 as 'I011' or should i use string to store the id?
item ID's are integers :p.
The ID is converted to an integer with this formula:
(256³ * N1) + (256² * N2) + (256 * N3) + (N4)​
N1-4 are the decimal ASCII codes for that character (1 would be 49, I is 73 and so on).

So yeah, nothing wrong with saving those as an integer.


also the message create item is xxx doesn't even display
Do the other messages appear? The name of the destructable and the coordinates?

Best thing you can do is debug the system, see exactly where it goes wrong.
Just place some BJDebugMsg's across the system, divided by waits. Then you can see exactly where the trigger stops, or where it crashes.

Also, there's nothing wrong with using "gg_trg_TreeDropWood".


Edit: I was too late, another victim has fallen to GUI D:
Well, JASS will still always be better than GUI (unless you really mess things up).
 

ABM

ABM

Level 7
Joined
Jul 13, 2005
Messages
279
ap0calypse
The other message display fine only the item one don't work

i tried to change i to itemtype since itemtype = 'I011'
but the bugger WE tell me it can't convert integer to item type
so i think it is crazy or it really hate me...

Arhowk
in the first post the trigger are the same as GUI but converted with the editor
all the point was to do the GUI with jass
ap0calypse told me to clean the trigger, but since i had no idea on how to, i took 2 different system about tree revival and tried to combine to this to make a trigger that look like jass and do what i want....but the result is not good...and even with the help of ap0calypse i couldn't make it look nice and clean, and , work at the same time. (i still wonder if the untouched converted trigger would work fine :p )
but GUI converted to Jass is not as efficient as human coded Jass (real Jass vs GUI to Jass)

PS: i still didn't gave up on converting it to Jass...(i kept it disabled but not deleted)
when i see all the clean coding Jass system, i really want to do the same and make best efficient trigger, but it look like it is too hard for my level.

i have a whole map of 100+ of GUI trigger to convert to Jass, some of them huge and most single to player to avoid bug (12 time same trigger) most of trigger linked together... so even if i can't find a way for this in Jass, there is still plenty for me to do converting :p
if i can convert all the map GUI trigger into efficient system and library i could probably increase by 50% the efficiency of triggers, and greatly increase the speed of the map.
 
Level 19
Joined
Aug 8, 2007
Messages
2,765
never name a variable "itemtype" as "itemtype" is a variable type like Integer, real, unit, etc.
 

ABM

ABM

Level 7
Joined
Jul 13, 2005
Messages
279
actually what i meant is that i change integer i ---> itemtype i
but the editor don't recognize 'I011' as an itemtype which is weird
because when converting GUI to Jass a trigger with itemtype variable called (itemtype but it could be called i or whatever, since it is GUI)
set udg_itemtype = 'I011'
when i try set i = 'I011' (i is a variable item type is say that integer cannot convert into itemtype.... so it look like integer i is better than itemtype i....

but that's weird :p
hate Jasssss !! but still wana learn :)
 
Level 19
Joined
Aug 8, 2007
Messages
2,765
itemtype in jass is not itemtype in GUI. itemtype in GUI is an integer in JASS. itemtype in JASS is like Charged, Artificial, etc.
 

ABM

ABM

Level 7
Joined
Jul 13, 2005
Messages
279
ok i redone all trigger from scratch...

here the first
[Jass=]
function JassTree_Check takes nothing returns nothing
local integer id = GetDestructableTypeId(GetEnumDestructable())
if id == 'ZTtw' or id == 'BTtw' or id == 'FTtw' or id =='ATtr' or id == 'B001' or id == 'B002' or id == 'B003' or id =='B004' or id == 'NTtw' then
call TriggerRegisterDeathEvent( gg_trg_JassDrop, GetEnumDestructable() )
call DisplayTextToPlayer(Player(0), 0.,0., "Tree Registration completed ")
endif
endfunction

function JassTree_Actions takes nothing returns nothing
call EnumDestructablesInRectAll( GetPlayableMapRect(), function JassTree_Check )
endfunction

//===========================================================================
function InitTrig_JassTree takes nothing returns nothing
set gg_trg_JassTree = CreateTrigger( )
call TriggerRegisterTimerEventSingle( gg_trg_JassTree, 1.00 )
call TriggerAddAction( gg_trg_JassTree, function JassTree_Actions )
endfunction[/code]

it seems to work fine



here is the second
[Jass=]
function JassDrop_Actions takes nothing returns nothing
local destructable tree = GetDyingDestructable()
local real x = GetLocationX(GetDestructableLoc(tree))
local real y = GetLocationY(GetDestructableLoc(tree))
local integer id = GetDestructableTypeId(tree)

if id == 'ZTtw' or id == 'BTtw' or id == 'FTtw' or id =='ATtr' then
call DisplayTextToPlayer(Player(0), 0.,0., "Tree and Wood")
call CreateItem( 'I011', x, y )
call SetItemUserData( GetLastCreatedItem(), 99 )
call RemoveDestructable( tree )
elseif id == 'B001' or id == 'B002' or id == 'B003' or id =='B004' then
call DisplayTextToPlayer(Player(0), 0.,0., "Bush and Tinder")
call CreateItem( 'I012', x, y )
call SetItemUserData( GetLastCreatedItem(), 99 )
call RemoveDestructable( tree )
elseif id == 'NTtw' then
call DisplayTextToPlayer(Player(0), 0.,0., "Deadtree and Petrifiedwood")
call CreateItem( 'I06A', x, y )
call SetItemUserData( GetLastCreatedItem(), 99 )
call RemoveDestructable( tree )
else
call DisplayTextToPlayer(Player(0), 0.,0., "Id isn't detected")
endif
endfunction

//===========================================================================
function InitTrig_JassDrop takes nothing returns nothing
set gg_trg_JassDrop = CreateTrigger( )
call TriggerAddAction( gg_trg_JassDrop, function JassDrop_Actions )
endfunction[/code]

it crash the map when i cut a tree, it doesn't display any of the debug message, it just crash.

what is wrong with the trigger?
is there problem using local?
 
Level 19
Joined
Aug 8, 2007
Messages
2,765
well for one u never registered an event for the second...

e/ oh theyre both connected.

do this

copy and paste this like

call BJDebugMsg("Test")

paste that after every line

in every paste, add a digit after Test

so like

set u = ###
call BJDebugMsg("Test1")
call RemoveUnit(u)
call BJDebugMsg("Test2")

e/ oh it crashes the map.. i should read

comment out all of the if then elself elseif... and before that big block print x,y, id, and GetHandleId(tree)
 

ABM

ABM

Level 7
Joined
Jul 13, 2005
Messages
279
ok i finally made the triggers works

register all tree in map into the next trigger
[Jass=]
function Trig_pickuptree_Check takes nothing returns nothing
local integer i = ( GetDestructableTypeId(GetEnumDestructable()))
if ((i == 'NTtw' or i == 'ATtr' or i == 'BTtw' or i == 'ZTtw' or i == 'FTtw' or i == 'B004' or i == 'B003' or i == 'B002' or i == 'B001')) then
call TriggerRegisterDeathEvent( gg_trg_DropTree, GetEnumDestructable() )
endif
endfunction

function Trig_pickuptree_Actions takes nothing returns nothing
call EnumDestructablesInRectAll( GetPlayableMapRect(), function Trig_pickuptree_Check )
endfunction

//===========================================================================
function InitTrig_pickuptree takes nothing returns nothing
set gg_trg_pickuptree = CreateTrigger( )
call TriggerAddAction( gg_trg_pickuptree, function Trig_pickuptree_Actions )
endfunction[/code]

when tree die drop item
[Jass=]
function Trig_DropTree_Actions takes nothing returns nothing
local integer i = ( GetDestructableTypeId(GetDyingDestructable()))
set udg_TempTree = GetDyingDestructable()
set udg_TempLoc = GetDestructableLoc(GetDyingDestructable())
if ((i == 'ATtr' or i == 'BTtw' or i == 'ZTtw' or i == 'FTtw')) then
call CreateItemLoc( 'I011', udg_TempLoc )
elseif ((i == 'B004' or i == 'B003' or i == 'B002' or i == 'B001')) then
call CreateItemLoc( 'I012', udg_TempLoc )
elseif ((i == 'NTtw')) then
call CreateItemLoc( 'I06A', udg_TempLoc )
endif
call DisplayTimedTextToForce( GetForceOfPlayer(Player(0)), 10.00, ( "You Cut " + GetDestructableName(udg_TempTree) ) )
call RemoveLocation(udg_TempLoc)
endfunction

//===========================================================================
function InitTrig_DropTree takes nothing returns nothing
set gg_trg_DropTree = CreateTrigger( )
call TriggerAddAction( gg_trg_DropTree, function Trig_DropTree_Actions )
endfunction[/code]

is this good or is there a way to improve these anymore?
 
Level 28
Joined
Jan 26, 2007
Messages
4,789
Again: don't use locations. By that I mean you should never use them.
Everything is more simple when using coordinates (to be taken literally).

"DisplayTimedTextToForce": same. It's just absurd. You display a text to all the players in a player group consisting of 1 player. Why not just send it to that 1 player?
Also, "GetForceOfPlayer" leaks. Leaks are very bad :).

GetPlayableMapRect(): use the variable (bj_mapInitialPlayableArea).
 

ABM

ABM

Level 7
Joined
Jul 13, 2005
Messages
279
Ok thank for repeating it ap0calypse.

but since the trigger crashed many time and after that even the GUI trigger started to crash i became paranoid, so i kept almost everything as origin and changed slowly....

i think what made the trigger crash is the remove destructible wich was at the end of the DropItem trigger...

so i will make the change as you said and check if everything still work fine...
i think i am traumatized by Jass :p (i didn't even use JassNewGen to be carefull, i used normal editor and basic Jass)

EDIT
after a few hours of testing and debugging
Here is my final product : a full Jass nicely coded and working function (it is still in two part but i am not sure it is possible to make in 1 part without bug)

[Jass=]
function Trig_B_Actions takes nothing returns nothing
local integer i
local destructable d
local real x
local real y
call DisableTrigger( GetTriggeringTrigger() )
set d = GetDyingDestructable()
set i = ( GetDestructableTypeId(d))
set x = GetLocationX(GetDestructableLoc(d))
set y = GetLocationY(GetDestructableLoc(d))
if ((i == 'ATtr' or i == 'BTtw' or i == 'ZTtw' or i == 'FTtw')) then
call SetItemUserData( CreateItem( 'I011', x, y ), 99 )
elseif ((i == 'B004' or i == 'B003' or i == 'B002' or i == 'B001')) then
call SetItemUserData( CreateItem( 'I012', x, y ), 99 )
elseif ((i == 'NTtw')) then
call SetItemUserData( CreateItem( 'I06A', x, y ), 99 )
endif
call RemoveDestructable( d )
call EnableTrigger( GetTriggeringTrigger() )
endfunction

//===========================================================================
function InitTrig_B takes nothing returns nothing
set gg_trg_B = CreateTrigger( )
call TriggerAddAction( gg_trg_B, function Trig_B_Actions )
endfunction[/code]

the first part didn't change (it pick all destructable of type tree and add them in the destructable_death_event to this trigger).


:)
the disable trigger is very important because it crash without, removing destructable is same as killing it (even when dead),
so without a wait it crash,
with a wait 0.00 and remove destructable it create two item because it run twice,
with disable trigger it run normally :p
 
Last edited:
Status
Not open for further replies.
Top