• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Adding local variables to GUI

Status
Not open for further replies.
Level 5
Joined
Feb 5, 2008
Messages
109
First post, first problem. ;)

I'm working on a map (surprise, surprise! ^^) with a few spells made by myself. A few days ago I found out about how to set variables local, but I still liked to use GUI instead of JASS. I read a tutorial explaining how to modify the world editor (adding new functions, see here), so I wanted to add a new function setting variables local. But the tutorial does not describe how to create a function not looking like for example "call DestroyEffect()".
So does anybody know how to create a function which says "local [xxx] udg_[xxx]"?
Would also be handy to have a GUI function to set the variable null.

Thanks =)
Triax
 
Last edited:
Level 19
Joined
Aug 24, 2007
Messages
2,888
WORKING ON A MAP OMG ?!!!

No you cant create a function that nulls a variable
I didnt get what you mean by that anyway

and functions look like "call DestroyEffect()"
what do you mean by setting variables to local ???
you cant make a function that creates a local variable

Edit: Welcome to Hive
 
Level 5
Joined
Feb 5, 2008
Messages
109
Anything wrong with the grammar or just irony? ^^ (am German)

If I want to create a custom spell and use waits, i need local variables, otherwise it might not work if there is another unit casting this spell. So that's how my trigger looks like now:
Code:
[b]Custom Script: [color=lightblue]local unit udg_Attacker[/color][/b]
Set [color=lightblue]Attacker[/color] = [color=lightblue](Attacking unit)[/color]
[i][...][/i]
Wait [color=lightblue]2.00[/color] seconds
[i][...][/i]
Kill [color=lightblue]Attacker[/color]
[b]Custom Script: [color=lightblue]set udg_Attacker = null[/color][/b]
But I want it to look like this:
Code:
[b]Set [color=lightblue]Attacker[/color] (variable type = [color=lightblue]unit[/color]) local[/b]
Set [color=lightblue]Attacker[/color] = [color=lightblue](Attacking unit)[/color]
[i][...][/i]
Wait [color=lightblue]2.00[/color] seconds
[i][...][/i]
Kill [color=lightblue]Attacker[/color]
[b]Set [color=lightblue]Attacker[/color] = [color=lightblue]null[/color][/b]
 
Level 7
Joined
Dec 31, 2005
Messages
712
I think (read this somewhere) that you should create a global variable with a name, and then declare a local variable with THE SAME NAME, starting with udg_.

This way, the local and the global will have exactly the same name, and the you can use the global in that trigger when in fact you will be using the local one.
 
Level 7
Joined
Feb 25, 2007
Messages
286
There is no gui action saying Null. (not to sure if this is what you want but you can do this)

  • Events:
  • Conditions:
  • Actions:
  • Custom script - call RemoveLocation(udg_blahblahblah)
<--- You dont need a function to do that. It kinda acts like a gui action just made by you using jass!

You can do that if thats what your asking. Pretty sure to "null" a unit you use the kill unit. If you want to completly get rid of it you do remove unit.. To be honest I have no idea if thats what you want or anything. Can you explain a little, its not because your german your typings acctually pretty good. Only problem is the way you word it. (but hey I'm american, this is my first language and I still suck at wording things)
 
Level 5
Joined
Feb 5, 2008
Messages
109
First of all, thanks for your compliment. =D

As I wrote I already know how to do this action in JASS, but though I'd like to use GUI 'cause it would be a relative command (if I change the name of the variable it's changed in the function without manual change) and would be a bit faster to create (but that's not so important).

I don't want to get rid of the unit, but the content of the variable. I read it will cause memory leaks if I don't set it null and it's used many times.

Actually my question was how to create this function for the WE by editing the TriggerData.txt. View this tutorial if you don't know what I mean.

Think it would be very helpful to talk to the creators of WEU or UMSWE. :?
 
Last edited:
Level 3
Joined
Jun 29, 2004
Messages
7
This works for units, but what if I want to set a lightning = 0? There is no possibility for this in GUI.

There are two possibilities.

1) Add presets for each data type that you want to be able to compare to null.

For example, in the presets for Units, we see:
Code:
// Units
UnitNull=0,unit,null,WESTRING_TRIGUNIT_NULL

You can do a similar thing with Lightning:

Code:
// Lightning
LightningNull=0,lightning,null,WESTRING_TRIGLIGHTNING_NULL

And of course you'd have to make a string for WESTRING_TRIGLIGHTNING_NULL -- "No lightning".

Then you can do a similar thing for every type (as many as desired).


2) Implement a full-on handle system. This is only worth it if you are using Handle Vars or something similar.

Here you would add the "handle" data type:

Code:
handle=0,0,0,WESTRING_TRIGTYPE_handle

And only one preset is necessary:
Code:
HandleNull=0,handle,null,WESTRING_TRIGHANDLE_NULL

Then you would need wrapper functions converting each type to handle (and optionally handle to each type -- using the return bug). It is a bit of tedious work, and you have to call unnecessary functions to convert from <type> to handle, but it fits well in the GUI framework.



As for your other question, I do not think it is possible. Those other things like Set Variable, Skip Remaining Actions (Return) and Custom Script are handled specially by the editor, and you can't add new actions that aren't of the form "call func(...)". You would have to edit the editor itself at a deeper level.

It's possible to edit the Custom Script action to allow whatever you want, but it only uses one parameter. In order for it to allow something like "local unit udg_myunit", you would need three parameters (a scriptcode, followed by an AnyType, followed by an AnyGlobal). I tried this, but it only used the first parameter. Of course, it would be unacceptable (in my opinion) to replace the Custom Script action with something else, anyway...


You might consider using handle variables and timers instead of local variables and waits. Waitless code runs much more predictably and you can get tighter times with timers than waits. I can understand any reservations in using this method, however, but consider it...
 
Level 15
Joined
Jan 16, 2008
Messages
1,244
i think the tutorial said something like this: local variables are checked before the global ones, so you can basicaly create a local variable with the same name as a global variable and next time you refer to the global variable, the data will be saved locally. Something like:

custom script - local unit udg_Attacker
set Attacker to (attacking unit)

Don't remember exactly but i think this makes it mui.
 
Level 5
Joined
Feb 5, 2008
Messages
109
Um, sorry ... The what? ^^ [edit] Handle to integer?

This is what I got:
Code:
[TriggerCategories]
TC_MyFunctions=WESTRING_TRIGCAT_MyFunctions,ReplaceableTextures\WorldEditUI\Actions-Nothing

[TriggerActions]
HandleNull=0,handle,null,WESTRING_TRIGHANDLE_NULL
_HandleNull_Defaults=_,_,_
_HandleNull_Category=TC_MyFunctions

[TriggerActionStrings]
HandleNull="Set Variable Null"
HandleNull="Set ",~Variable," = ",~Value," / ",~Text
HandleNull=

[WorldEditStrings]
WESTRING_TRIGCAT_MyFunctions=Eigene Funktionen
WESTRING_TRIGTYPE_handle=Handle
WESTRING_TRIGMHANDLE_NULL="Kein Wert"

[i][edit][/i]
handle=0,0,0,WESTRING_TRIGTYPE_handle

H2I=0,1,integer,handle
_H2I_Defaults=GetUnitStateSwap
_H2I_Category=TC_CONVERSION

H2I="Convert Handle To Integer"
H2I="Integer(",~handle,")"
H2IHint=

H2R=0,1,real,handle
_H2R_Defaults=GetUnitPointValueByType
_H2R_Category=TC_CONVERSION

H2R="Convert Handle To Real"
H2R="Real(",~handle,")"
H2RHint=
It's not working yet. The function is displayed, but i can't choose a variable (blank window pops up). If i try to set a value/text, WE collapses. I'm not sure about this value/text thing, but if I don't use 3 values in the action string, I get an error.

[edit]
I've read your post again. I would need to create a whole convert system? Damn, that's quite a lot of work ... Don't think it's worth it.
Converting doesn't work. Get a blank window. :S
 
Last edited:
Status
Not open for further replies.
Top