HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Some Custom Text questions...

02-19-2003, 01:28 PM#1
BoddoZerg
A few Custom Text questions for those who know:

1) How do you put a line break into a string? |n doesn't seem to work.

2) How do you make a local Unit or Point variable? What about Unit Groups?

3) Is it possible to pass Units and Points to another function? For example, "function DeathCoil takes unit CoilCaster returns nothing".

4) Can you use the same trigger to create multiple triggers with the same name, or do you have to use a Trigger Array? Do trigger arrays even work?

5) Does creating and destroying multiple triggers cause a memory leak?
02-19-2003, 02:01 PM#2
FyreDaug
1)You have to use |n|n to make it look like this:
Line 1

Line 2

2)I think you mean how do you store a unit in a variable, simply create a unit variable and add whatever unit you like into it.

3)I don't understand

4)You can't have more than 1 trigger with the same name.

5)Maybe, maybe not - if it does (I've never done it) just delete them gradually, instead of all at once.
02-19-2003, 02:09 PM#3
BoddoZerg
1) I haven't been able to get that to work. I type:
Code:
call DisplayTextToForce(GetPlayersAll(),"Line 1|n|nLine 2")
In game it shows up as : "Line 1|n|nLine2". The line breaks aren't doing anything at all.

2) No, I mean local variables. "local Unit SomeUnit" doesnt seem to compile.
02-19-2003, 02:10 PM#4
PitzerMike
2) you can have all types of local variables, you must however declare them at the beginning of your function like this
local unit xxx [= initial value, if you have one]

3) yes, you can have all sorts of variables be returned or taken by your functions, you can only have one var be returned but you can take lots of parameters for the input

4) you have to use trigger arrays, but that isn't a problem using a loop and an index

5) I had a map where I created and destroyed more than 3000 triggers without becoming laggy

EDIT: Just saw your new post: JASS is case sensitive, so you have to use unit and not Unit

and I guess you shouldn't have the |n within the quotes because then it is seen as part of the string and will be shown as it is
02-19-2003, 02:12 PM#5
Aiursrage2k
1) How do you put a line break into a string? |n doesn't seem to work.
|n --for most functions creates a newline, for some it does not.

2) How do you make a local Unit or Point variable? What about Unit Groups?
Declare your variables using local at the top of the function.
example
local unit x
local group whichgroup
I do remember all the variable types, the best way to do this, is make a new map, put one of each variable type, then export the script open it up, and it will tell you all the variable types. I think you use argument null, prehaps for overloading functions.

3)Is it possible to pass Units and Points to another function? For example, "function DeathCoil takes unit CoilCaster returns nothing".
Should work.

4) Can you use the same trigger to create multiple triggers with the same name, or do you have to use a Trigger Array? Do trigger arrays even work?
I do not know, but trigger arrays do work.

5) Does creating and destroying multiple triggers cause a memory leak?
I do not know, but more then likely.

Problem: You create a function in trigger x, and want to call it from trigger y.

Option1: each trigger that requires it, has its own case of the function, but with a different name
[drawback, much code redundancy, more wasted space]

Option2: make trigger X only contain one function, send parameters using user globals and then execute trigger x, from trigger y.
[drawback, have to use user global variables]

Option3: put your function into blizzard.j
[drawback, can not work unless you have the exe, and can not work on battle.net]

Option4: do your entire code in the map.j file
[drawback, if you were to go back in World edit and save your map you would need to redo it]

Option5: do the all the triggers in one function
[drawback, obvious]

It seems to me like there is no good solution to this, I guess you should pick the solution that best works for the situation. I dont see what would have been so difficult to be able to call a function that is within a different trigger, especially since the functions can not have the same name.
02-19-2003, 02:23 PM#6
weaaddar
To do carriage returns is actually quite difficult.
But the easier way (although might look messy) is to do this
call DisplayTextToForce(GetPlayersAll(),"Line 1
Line 2")
Just hit enter after the end of the line, it works with dialog messages so I'm pretty sure it should work in normal text.
2) a Very important note is that for Local variables they must be defined at the VERY TOP of the function and that they are in all lowercase letters (except the var name that can be anything you want it to be)
3) Yes, you can even take function outputs and put them here.
Like Ridiculusfunc takes Funcs(UnitKiller) returns nothing
4) Yeah you can have multiple local triggers named the same exact thing, they will still run if they are waiting for an event to occur. (Example code is the melee victory defeat functions in blizzard.j)
5) Yes Jass is a poorly optomized language and is known to memory leak. Thus having 400 triggers is a terrible idea, and aiming for 40. Also note that it depends what your trigger does, If you have 400 triggers that do nothing and you delete them all it will cause a very minor memory leak, but if you 400 complex which create a polynomygraph and you delete those you will create a larger memory leak.

Also note that units which die stay in memory, units which are removed stay in memory, and units which exploded stay in memory but those which died and those which exploded only retain quantitive data (Like which player killed them and there point value), those which were removed retain all data.
02-19-2003, 02:47 PM#7
PitzerMike
There is a trick to use functions of other triggers:

In the trigger where you call this function make a dummy function at the top just to be able to validate the trigger

as soon as this is done, comment out the dummy function (//) and it should work because in the map.j everything will be put together anyway

the trigger with the called function must however be above the calling trigger
02-19-2003, 02:57 PM#8
BoddoZerg
Okay, I guess my problem was putting "Units" in uppercase. Silly me.

Units that died and are removed stay in memory? o_O That explains where those massive memory leaks come from. >.<

Now if only there was a way to pass local variables across "ForGroup" calls. =(
02-19-2003, 05:56 PM#9
weaaddar
The memory use chain works as fallowing
Living Units>Removed Unit>Dead Units>Dead Units without corpses (88 seconds after death)=Exploded Units.
So its prefered to use exploded units.
However the memory use isn't that extreme its when you start having absurd amounts of units that it does come problematic. Dead units remember there unit for about 88 seconds because they can be revived via Resurection spell or used in Meat Wagon. So a madness type game can be very problematic if you have about 400 units fighting and 400 units dead, and you explode every corpse on the field you'll still probably feeling some serious lag.
War3 seems to have better optomized code for slow amounts of kill if you were to kill about 1000 in 1 second you would get crazy lag, but if you were to spawn then kill 10 units every 10 seconds for a 1000 you will get lesser almost unnoticible lag.
02-19-2003, 06:48 PM#10
Aiursrage2k
Quote:
Originally posted by BoddoZerg
Okay, I guess my problem was putting "Units" in uppercase. Silly me.

Units that died and are removed stay in memory? o_O That explains where those massive memory leaks come from. >.<

Now if only there was a way to pass local variables across "ForGroup" calls. =(


Made this a while ago, it takes group, you could add more parameters to take if need be.

ForGroup2 takes group whichGroup returns nothing
local unit xy = null
local integer n = CountUnitsInGroup(whichGroup)
set bj_forLoopAIndex = 1
set bj_forLoopAIndexEnd = n
loop
set xy = null
exitwhen bj_forLoopAIndex > bj_forLoopAIndexEnd
set xy = FirstOfGroup(whichGroup)
//xy is your unit
call GroupRemoveUnitSimple( xy, whichGroup )
set bj_forLoopAIndex = bj_forLoopAIndex + 1
endloop
endfunction
02-19-2003, 06:53 PM#11
Guest
Quote:
3) Yes, you can even take function outputs and put them here. Like Ridiculusfunc takes Funcs(UnitKiller) returns nothing

That's very interesting, but how is this useful? Seems like you could just use...

function Ridiculusfunc takes unit UnitKiller returns nothing
local unit x = Funcs(UnitKiller)

Or I'm I misunderstanding that use?

....................

On another note, I posted this in the JASS forum and might as well mention it here also...

[repost from AI & JASS Vault]
Someone over in the map dev forum talked me into doing a custom text trigger tutorial. If you've seen my spell editing tutorial, it will be similar...

Anyway, I'm looking for feedback and input on the tutorial. If your're interested in reading over it and adding your $.02, please PM me with your e-mail address and I'll send it to you.

Right now, the tutorial covers:
what is custom text
why would I use it
how do I learn
how to define and use functions
how to use an if/then statement (and embedded if/then)
how to use a loop
global and local variables
no forward references
how and why to //comment

What I'd like the tutorial to do is get them going enough to be able to halfway understand the more complex concepts in Magnus99's reference manual.
02-19-2003, 06:54 PM#12
FyreDaug
Is there a way to clear the memory of units that you aren't going to refer to at all? Say some peasants die, can you wipe them just out of the memory? Or just use the same unit ID to remove it from the memory?
02-19-2003, 07:31 PM#13
Aiursrage2k
Taking functions as arguments... its used by the ForGroup function, which the first arg is a unit group and the second is a function.
02-19-2003, 08:04 PM#14
Guest
Ah...I see... That could be helpful.
02-19-2003, 08:11 PM#15
FyreDaug
*Thinks he should learn JASS*