• 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.

[vJASS] Was wondering what I did wrong? Random tree respawn....

Status
Not open for further replies.
Level 5
Joined
Aug 8, 2008
Messages
113
JASS:
scope Ashenvale
globals
 location des01
 destructable des02 = GetDyingDestructable()
endglobals

function Trig_Ashenvale_Conditions takes nothing returns boolean
    if  ( GetDestructableTypeId(GetDyingDestructable()) == 'ATtr' ) then
        return true
        else 
        return false
    endif
    
endfunction

function Trig_Ashenvale_Func001Func001C takes nothing returns boolean
    if  ( GetRandomInt(1, 10) >= 0 ) then
        return true
        else 
        return false
    endif
  
endfunction

function Trig_Ashenvale_Func001A takes nothing returns nothing
 



    if ( Trig_Ashenvale_Func001Func001C() ) then
        set des02 = GetDyingDestructable()
        set des01 = GetDestructableLoc (des02)
        call RemoveDestructable( des02 )
        call CreateDeadDestructableLocBJ( 'GTsh', des01, GetRandomDirectionDeg(), 1, 0 )
        set des02 = GetLastCreatedDestructable() 
        call DestructableRestoreLife( des02, GetDestructableMaxLife(des02), true )
        
    else
        call DestructableRestoreLife( GetDyingDestructable(), GetDestructableMaxLife(GetDyingDestructable()), true )
    endif
endfunction

function Trig_Ashenvale_Actions takes nothing returns nothing
    call EnumDestructablesInRectAll( GetPlayableMapRect(), function Trig_Ashenvale_Func001A )
endfunction

//===========================================================================
function Ashen takes nothing returns nothing
    set gg_trg_Ashenvale = CreateTrigger(  )
    call TriggerRegisterDeathEvent( gg_trg_Ashenvale, des02 )
    call TriggerAddCondition( gg_trg_Ashenvale, Condition( function Trig_Ashenvale_Conditions ) )
    call TriggerAddAction( gg_trg_Ashenvale, function Trig_Ashenvale_Actions )
endfunction

endscope
I saved it twice with no errors.... so when i go to test it.
it takes me to the title screen.....
 
Also I wonder when function Ashen will be fired.

GetDyingDestructable() --> GetTriggerDestructable()

JASS:
if  ( GetRandomInt(1, 10) >= 0 ) then
        return true
        else
        return false
    endif
can be simpliefied to -->

return ( GetRandomInt(1, 10) >= 0 ) (but read what Cataract92 wrote)

The same way you can simplify the functionTrig_Ashenvale_Conditions

^But actually you don't even need this seperated condition function. Just use an if/else in the other function to make the check.

Also you don't need names anymore like function Trig_Ashenvale_Func001A... that's good point in jass, you can make it much more readable. And in the end you always get a smarter looking trigger and find bugs much faster.
 
Level 23
Joined
Apr 16, 2012
Messages
4,041
I dont know why it doesnt compile, but this will never work anyways, because you pass to the call TriggerRegisterDeathEvent( gg_trg_Ashenvale, des02 ) the des2 is null and the events dont get registered again when des02 runs, you should make the trigger global and when you init you should enumerate all trees and call the function with the enumerated tree

As others pointed out, the code can be optimized greatly
 
Level 5
Joined
Aug 8, 2008
Messages
113
You cannot call this in the globals block.

destructable des02 = GetDyingDestructable()
.
JASS:
call TriggerRegisterDeathEvent( gg_trg_Ashenvale, des02 )
how can I make sure this checks for a dead tree then?

Also you shouldn't use BJs when using jass..
Is it always wrong to use BJs or are there cases when using it will be better?
You should look at my tutorial Converting GUI to efficient JASS. Link is in my sig below.
Will do
Also I wonder when function Ashen will be fired.
I couldn't figure out what the initiation trigger was.....what I have is what was in the tutorial for scope. minus converting the trigger into a local.
GetDyingDestructable() --> GetTriggerDestructable()
But how will it know if the destructable is dying and not just being created or revived?
JASS:
if  ( GetRandomInt(1, 10) >= 0 ) then
        return true
        else
        return false
    endif
can be simpliefied to -->

return ( GetRandomInt(1, 10) >= 0 )
Im confused
how will this check to see if there is a random number between 1 and 10.....(also I made it everything greater than 0 to check if the trigger worked)
but once I know that it works correctly I will change it to everything greater then or equal to 7 creates underground tree and everything lower than or equal to 6 will create an ashenvale tree.
(but read what Cataract92 wrote)

The same way you can simplify the functionTrig_Ashenvale_Conditions

^But actually you don't even need this seperated condition function. Just use an if/else in the other function to make the check.
Im not good at using if then/else functions... I understand the concept but putting it into practice doesn't reap my results.
Also you don't need names anymore like function Trig_Ashenvale_Func001A... that's good point in jass, you can make it much more readable. And in the end you always get a smarter looking trigger and find bugs much faster
I was trying to change one thing at a time. I know it takes longer that way but it makes it easier to find bugs for me. If I screw up and make a bunch of changes it makes it harder to find things.

And ( GetRandomInt(1, 10) >= 0 ) is always true
I set it that way to check if the trigger worked or not.... I will change it to >=7 when I know that it functions the way I want to
I dont know why it doesnt compile, but this will never work anyways, because you pass to the call TriggerRegisterDeathEvent( gg_trg_Ashenvale, des02 ) the des2 is null and the events dont get registered again when des02 runs,
JASS:
// you should make the trigger global
I didn't make the trigger global because I haven't figured out how to do that yet. I tried it but there is something im not doing.
JASS:
//and when you init 
//you should enumerate all trees and
 //call the function with the enumerated tree
How would I do those three things?
As others pointed out, the code can be optimized greatly
I haven't optimized it because I don't want to mess anything up beyond what I already did and partially because I some things I just don't know. For example how to get it to recognize dying trees without using getdyingtrees function. or initiate a initiation trigger how to get global triggers to initiate... how to get if then else then functions to work......
 
JASS:
call TriggerRegisterDeathEvent( gg_trg_Ashenvale, des02 )
how can I make sure this checks for a dead tree then?

You have to register all trees in your map using loops for them to get caught by this event.

Is it always wrong to use BJs or are there cases when using it will be better?[/quote]

They will never be better to use than simply calling natives. But in some cases they are acceptable as it reduces the lines you do.

I couldn't figure out what the initiation trigger was.....what I have is what was in the tutorial for scope. minus converting the trigger into a local.

There are better tutorials for scope. If initialization was not covered in the one you read you should read another.

But how will it know if the destructable is dying and not just being created or revived?

The event only registers dying destructables. Thus only dying destructables will fire the event. Also if you look at dying destructable it calls triggering destructable.

Im confused
how will this check to see if there is a random number between 1 and 10.....(also I made it everything greater than 0 to check if the trigger worked)
but once I know that it works correctly I will change it to everything greater then or equal to 7 creates underground tree and everything lower than or equal to 6 will create an ashenvale tree.

Im not good at using if then/else functions... I understand the concept but putting it into practice doesn't reap my results.

The return is used to simply return a boolean. It evaluates the conditions and returns true or false. If you need a function to do 2 or more things that are different then you need to stick with an ITE. You should check out my tutorial Converting GUI to efficient jass. It will show you some efficient methods when using jass.

I was trying to change one thing at a time. I know it takes longer that way but it makes it easier to find bugs for me. If I screw up and make a bunch of changes it makes it harder to find things.

Use debug messages to easily find errors / bugs in scripts.
 
Level 23
Joined
Apr 16, 2012
Messages
4,041
you shouldnt use most of the globals, some of them are fine, many of them leak handle Ids and some of them leak objects, one of them even desyncs the game

the way you have to set this up is around this:

JASS:
scope myScope initializer init
    globals
        private trigger tr = CreateTrigger()
    endglobals

    private function onLoadEnum takes nothing returns nothing
        call TriggerRegisterDeathEvent(tr, GetEnumDestructable())
    endfunction

    private function init takes nothing returns nothing
        call EnumDestructablesInRect(GetWorldBounds(), null, function onLoadEnum)
        call TriggerAddCondition(tr, ...)
        call TriggerAddAction(tr, ...)
    endfunction

the code is incomplete, I left out your part of the code, but this is roughly how it should be

Please note that this does not work for trees that are created after map has been initialized(CreateDestructable... is called)
 
Level 5
Joined
Aug 8, 2008
Messages
113
By the way + rep for everyone even the guys that helped me out in converting a local into a unit in my other thread.

You should check out my tutorial Converting GUI to efficient jass.

Ok this will be a long list of things
Main Ideas
1. Ultimate Guide to Coding
2. Tutorial interpretation
3. How to improve.
4. My understanding of how code worked
5. ways of learning.
7. my understanding of
8. debugging
9. explanation of most guides.

Tutorial Interpretation
My interpretation of your tutorial is that it is unfinished. It explains information I already know and information I don't know lacking data that would help me understand.

For example I already know about the functions. Maybe link to another guide that already covers that. Also your explanation of Functions is kind of lacking. You just say function name without stating that or how the name can be manipulated. I don't get that what ever name I put in call action trigger (function "what ever I want to call it")
has to be the same Function "what ever I called it in the action trigger"

How to Improve
I find that lacking in alot of guides actually. The perfect set of guides would state how information can be manipulated and how material within the editor interact. Instead of just giving examples to copy.
The perfect guide would list all natives, and how they can be manipulated.
List all Bjs and how they should be manipulated and when to use them and when not to. How to get rid of any leaks/desyncs that they would produce
List all variable types and how and when to convert, manipulate, use, etc.
Compile together in one guide structs, functions, libraries, scopes, etc and list how they should be manipulated.
List all trigger initiators and how to get them to function the way you want them to what every possibility is. Also work arounds. For example, the guy below gave me code for getting trees to revive on presets from initiation but it doesn't explain how to get all trees to revive how I want them too.

Learning Styles
Also keep in mind peoples learning styles, the ultimate set of guides would keep peoples learnings styles in mind. Currently, most guides only use one or two learning styles.

Debugging
A good guide would tell you how to debug yourself. And when to come for help. How to recoginize when something is leaking, or desyncing. Basically how did you come up with that information.

Misinformation
Also a list of other guides to start with. Because atm alot of the guides are alot to read through and some of them are outdated or misinformative. For example one guide told me that any native is recognizable if it comes after "call"
and also I didn't know BJs and Natives could be insterted into other parts of the script. I thought Bjs and Natives were just the actions. again thats how it was explained to me.
Like I said a thorough explanation of all natives and bjs would be helpful and also how each code interacts.

Further reading
A guide could be made for explaining the further where other guides didn't go.

Loop and If then/else
If then else isn't explained to well in guides. It just says
If Condition
Then
Action
else action
or If condition
Then action
else if condition
then action
else
action
that bit of code is more complicated then that. I've found out through experimenting that sometimes do nothing is needed to make the code work. Or sometimes certain and ite need to be placed inside another ite to work. Or placed inside a loop.

Guides don't explain this bit of information and it would be helpful to have an indepth explanation of the if/then else and loops

What needs to be done?
four or five experienced people should get together to make guides but they should also bring along 30 to 40 unexperienced coders to make sure everything is clear. Half are Totally inexperienced / the other Half are Inexperienced at world editor but experienced at other languages.
Then they should write a comprehensive guide series to explain all the nuts and bolts of coding. I imagine that this would branch off into two routes. One for each newbie group.

why so many test readers and contributers.
Four or five contributers would help make sure that the code is flexible enough to include different styles of coding. While 30 to 40 people should be. done like this
test guide one 5 people
if they find faults fix
test on the same 5 people
repeat steps with another group of 5
repeat steps until no more inexperienced people are left.

I don't know another language so a lower amount might be needed for the group having those prereqs..

you shouldnt use most of the globals, some of them are fine, many of them leak handle Ids and some of them leak objects, one of them even desyncs the game

the way you have to set this up is around this:

JASS:
scope myScope initializer init
    globals
        private trigger tr = CreateTrigger()
    endglobals

    private function onLoadEnum takes nothing returns nothing
        call TriggerRegisterDeathEvent(tr, GetEnumDestructable())
    endfunction

    private function init takes nothing returns nothing
        call EnumDestructablesInRect(GetWorldBounds(), null, function onLoadEnum)
        call TriggerAddCondition(tr, ...)
        call TriggerAddAction(tr, ...)
    endfunction

the code is incomplete, I left out your part of the code, but this is roughly how it should be

Please note that this does not work for trees that are created after map has been initialized(CreateDestructable... is called)
how would I get it to work for trees created after the map is initialized? Also I thought Inits couldn't be included in scope?
Lastly, How come your use of globals are ok but mine are not?
 
Level 23
Joined
Apr 16, 2012
Messages
4,041
it is because you use global variables, yet you would be able to achieve the very same thing with local variables, so you dont need globals at all

initializers in order of Vexorians(standard) JassHelper:
module initializer
struct initializer
library initializer
scope initializer
InitTrig function

module and struct initializers are called via ExecuteFunc, so they run in their separate thread. Library, scope and InitTrig run in the main thread and all this code is injected into function that is marked as main, which is inaccessable by standard means

Note that Cohadar's JassHelper has different order, I think it is:
library initializer
scope initializer
struct initializer
module initializer
InitTrig function

but it may be shuffled a bit

all those are valid

Example of all of those: http://www.hiveworkshop.com/forums/pastebin.php?id=7ioi03


What about destructables created on fly.

I dont think there is event for when destructable enters map, so you either have to run periodic timer recreating the trigger with all the trees on map, or you can hook the CreateDestructable functions
 
initializers in order of Vexorians(standard) JassHelper:
module initializer
struct initializer
library initializer
scope initializer
InitTrig function

Note that Cohadar's JassHelper has different order, I think it is:
library initializer
scope initializer
struct initializer
module initializer
InitTrig function

Just to clarify, Cohadar's JassHelper actually has the exact same order as Vexorian's. (module > struct > library > scope > InitTrig) The only difference is that Cohadar's takes into account when one library requires another. For example, if library B requires library A:
JASS:
library A initializer Init
    private function Init takes nothing returns nothing
        call BJDebugMsg("A")
    endfunction
endlibrary

library B requires A
    private struct Example
        private static method onInit takes nothing returns nothing
            call BJDebugMsg("B")
        endmethod
    endstruct
endlibrary

In vexorian's jasshelper, it would display "B" then "A".
In cohadar's jasshelper, it would display "A" then "B".

Cohadar's version is correct for initializers. It only makes sense for the libraries that you require to have their initializers run first. Vexorian's does this when you have the same initializer (e.g. if A and B both had struct initializers, A would run before B), but the issue is that modules will always run before struct initializers, struct initializers will always run before library initializers, etc. :)
 
This should be in my tutorial page.

Tutorial Interpretation
My interpretation of your tutorial is that it is unfinished. It explains information I already know and information I don't know lacking data that would help me understand.

It is finished.

For example I already know about the functions. Maybe link to another guide that already covers that. Also your explanation of Functions is kind of lacking. You just say function name without stating that or how the name can be manipulated. I don't get that what ever name I put in call action trigger (function "what ever I want to call it")
has to be the same Function "what ever I called it in the action trigger"
There is a link to a tutorial better describing them down below.

How to Improve
I find that lacking in alot of guides actually. The perfect set of guides would state how information can be manipulated and how material within the editor interact. Instead of just giving examples to copy.
The perfect guide would list all natives, and how they can be manipulated.
List all Bjs and how they should be manipulated and when to use them and when not to. How to get rid of any leaks/desyncs that they would produce
List all variable types and how and when to convert, manipulate, use, etc.
Compile together in one guide structs, functions, libraries, scopes, etc and list how they should be manipulated.
List all trigger initiators and how to get them to function the way you want them to what every possibility is. Also work arounds. For example, the guy below gave me code for getting trees to revive on presets from initiation but it doesn't explain how to get all trees to revive how I want them too.
This is a GUI tutorial so structs, libraries, scopes are useless here.
Also listing all natives is not needed as GUIers don't use them much and they can find the ones they need if they do. Plus there are to many of them. function initiators ?

Learning Styles
Also keep in mind peoples learning styles, the ultimate set of guides would keep peoples learnings styles in mind. Currently, most guides only use one or two learning styles.
Yes I know this. But that is how the tutorial is staying.

Debugging
A good guide would tell you how to debug yourself. And when to come for help. How to recoginize when something is leaking, or desyncing. Basically how did you come up with that information.
If you read I did describe how to do this.

Misinformation
Also a list of other guides to start with. Because atm alot of the guides are alot to read through and some of them are outdated or misinformative. For example one guide told me that any native is recognizable if it comes after "call"
and also I didn't know BJs and Natives could be insterted into other parts of the script. I thought Bjs and Natives were just the actions. again thats how it was explained to me.
Like I said a thorough explanation of all natives and bjs would be helpful and also how each code interacts.
The tutorial does not have outdated information. I have no idea what you mean by natives are recognizable after call. BJs and Natives can be inserted into other parts of the script makes no sense either.

Further reading
A guide could be made for explaining the further where other guides didn't go.

Loop and If then/else
If then else isn't explained to well in guides. It just says
If Condition
Then
Action
else action
or If condition
Then action
else if condition
then action
else
action
that bit of code is more complicated then that. I've found out through experimenting that sometimes do nothing is needed to make the code work. Or sometimes certain and ite need to be placed inside another ite to work. Or placed inside a loop.
Guides don't explain this bit of information and it would be helpful to have an indepth explanation of the if/then else and loops
ITEs and Loops are covered in basic tutorials. Also Do nothing action is never needed. All it does is call an empty function so it cannot make something work. It can make something not work if it causes it to hit the op-limit.

What needs to be done?
four or five experienced people should get together to make guides but they should also bring along 30 to 40 unexperienced coders to make sure everything is clear. Half are Totally inexperienced / the other Half are Inexperienced at world editor but experienced at other languages.
Then they should write a comprehensive guide series to explain all the nuts and bolts of coding. I imagine that this would branch off into two routes. One for each newbie group.

why so many test readers and contributers.
Four or five contributers would help make sure that the code is flexible enough to include different styles of coding. While 30 to 40 people should be. done like this
test guide one 5 people
if they find faults fix
test on the same 5 people
repeat steps with another group of 5
repeat steps until no more inexperienced people are left.

I don't know another language so a lower amount might be needed for the group having those prereqs..
This is not needed as I have already had more than a few thousand say this guide helped them a lot. Also when I made this I did not know any languages besides GUI / Jass / vJass.

If you want to continue the talk on my tutorial please do it in my tutorial page so it does not clutter this thread with things that have nothing to do with this thread.

how would I get it to work for trees created after the map is initialized? Also I thought Inits couldn't be included in scope?
Lastly, How come your use of globals are ok but mine are not?
I believe edo494 meant to say BJs not globals in that.
 
Status
Not open for further replies.
Top