jass, custom scripts, and local variables...

Grundy

Ultra Cool Member
Reaction score
35
i have some questions regarding jass, custom scripts, and local variables. these questions may have been answered somewhere else but i cant find it, and when i search for these things it just comes up with topics where people tell someone they should have used local variables for something and none of it explains anything.

please dont answer these questions unless you really know what you're talking about. i would rather have no information than the wrong information. like my question about pointers, don't just automatically say no because you havent seen it or dont know how, only answer if you know for sure and personally have tried and searched for it.

first, does jass let you make your own data types? like struct and class in c++.

does jass have pointers?

multi-dimensional arrays: i know you cant make them in the gui variable thing, but can you make them when you are coding in jass?

how do you make local arrays? is it something like... local integer array[5] to create a local array of 5 integers?

if i use a custom script to make a local integer named count in a trigger, can you use the local variable as the variable for the "For Each Integer Variable, Do Multiple Actions" gui action?

In jass, is there a while loop or a do-while loop? i have been doing it a cheap way where i use an integer variable in a for loop and inside the loop from 1 to 2 and inside the loop i use an if/then/else to check the conditions i want, if its true i set the integer to 1, if its false i set the integer to 2, so if its true it will go through the loop again because its a 1 again but if its false it stops looping because i set it to 2 and thats the last number so it breaks out of the loop. i'd like it if i could just use a while or do-while loop instead.

also, i dont expect someone to explain it here, but can anyone (Vexorian) point me to where i can find something on how to use game caches to use hash tables?
 
how do you make local arrays? is it something like... local integer array[5] to create a local array of 5 integers?
Just use "local integer array IntArrayName"

if i use a custom script to make a local integer named count in a trigger, can you use the local variable as the variable for the "For Each Integer Variable, Do Multiple Actions" gui action?
Nope, since the "multiple actions" is a function and the conditions too

also, i dont expect someone to explain it here, but can anyone (Vexorian) point me to where i can find something on how to use game caches to use hash tables?
Save all values in one category... Create some funcs to make it easier.
 
ok, the array thing helps, but does that make it an array of any size? can you specify the size of the array?

and the game cache thing, thanks for trying to help but i dont get it. anyone know where i can see examples of how its used? i looked at vexorian's invx map but i see all these functions being called and i cant find those function definitions anywhere
 
Grundy said:
ok, the array thing helps, but does that make it an array of any size? can you specify the size of the array?
I never understood why you need to specify an array size. Why do you need it to be a specific size?
 
well dont you think its more efficient if you only take 5 integers instead of having it give you 1000 that you dont need? unless jass "arrays" are more like linked lists where they dont have to all connected in a row, but thats usually how arrays work. i dont understand how you can have an array withOUT a specific size. i know you can (with roc for example, and other programing languages like perl) i just dont understand how that works. all i know is c++ gives you a specific size that you can store stuff in and doesnt give you more than you ask for and need, if it gives you an ulimited amount of space how does it know where it can store the next variable you want to use without interfering with the array?
 
Does jass let you make your own data types? like struct and class in c++?

Yes. http://jass.sourceforge.net/doc/globals.shtml

Does jass have pointers?

Technically, yes. The "Handle" and "Code" types could be considered pointers since they point to a data structure defined in WC3. However there are no pointers in the C/C++ sense that may be used in JASS beyond the "return type bug".

Multi-dimensional arrays: i know you cant make them in the gui variable thing, but can you make them when you are coding in jass?

Nope. You may simulate them (poorly in my opinion) with functions however.

How do you make local arrays? is it something like... local integer array[5] to create a local array of 5 integers?

Already been answered. Also I must note that unlike Java or C++ that arrays in JASS do not have a defined upper bound for indexes other than what is defined in common.j as JASS_MAX_ARRAY_SIZE, which is 8192. When you specify a size in the GUI that simply initalizes the array up to the index you enter.
EDIT: This means that in JASS all arrays are defined as (in a way similar to C)

Code:
Array_Name array type[8192];

If i use a custom script to make a local integer named count in a trigger, can you use the local variable as the variable for the "For Each Integer Variable, Do Multiple Actions" gui action?

If by this you mean that you want a locally defined variable for use in a loop, then you can.

Code:
function
...
local integer count = SomeFunction()
     loop
          set count = count  + 1
          call DoSomething()
          call DoSomethingElse()
          exitwhen iterations > 10
     endloop
...
endfunction

However, if you would like to use that variable in another function, then no, you cannot.

In jass, is there a while loop or a do-while loop?

There is no built in while or do-while syntax, you could write functions to do this for you however.

where i can find something on how to use game caches to use hash tables?

I assume you would like to hash values into a game cache for use among multiple functions without the use of global variables. If you understand how hash tables work in Java or C++ it wouldn't be too hard to either:
A) Write something to do it for you or
B) Modify Vexorian's Attach Handle Variable system to your own needs.

If you look at the API functions on this page, http://jass.sourceforge.net/doc/api/common_j-types-gamecache.shtml you should be able to come up with something that fits your needs.

Good luck and I hope this helped!

http://jass.sourceforge.net is your friend!
 
hmm source forge tells you that you can make your own types and it tells you how to start it but it doesnt actually say how to do it or how to access those types.

what im trying to do something somewhat equivalent to this in c++

struct blablah
{
int size
char code
};

except i actually want it to be like this in my map (using incorrect syntax to more resemble c++ instead of jass)
struct playerhero
{
unit hero;
item weapon;
integer whatever_i_want;
}

and i want to create an array of these "playerhero" data types and i need a way to access the integer inside it, in c++ you would do...
playerhero redhero;
redhero.whatever_i_want = 10;

now for jass im guessing it would start as....

type playerhero extends hero //so its derived from a hero, it would have all the hero things, but i want to add 2 more things to it.
now i have no idea what to do after that. i dont know how to add to it, how to end the type declaration, or how to access something inside of it.
 
As they say, therein lies the rub. There is no easy way to create player constructed data types as they are hard coded in WC3. You could attempt something of the sort with gamecaches, but that would probably be painfully slow. =/

JASS definately has its problems. I like my object oriented programming ; ;
 
so what is the point of the "type new_type extends blahblahblah" thing then? what does that even do?
 
"Game Variables" instead of "Game Constants" would also make mapping a whole lot easier. if you could change a constant any time you wanted in a map....
 
ok that thing opens up some more questions now...

the data type "playercolor", how can that be used? can you use a playercolor variable for things such as: minimap ping colors (ping location action), game text color (display message to players), changing the color of a unit (making player 1's hero the blue color instead of red?), any other way to use this variable? or is it only used on conditions, like to check the color of a player?

also the event response Damage Source, obviously its the source of damage that a unit takes, but what exactly IS it? if i cast a spell on a unit is the damage source then the spell or the unit that cast the spell or something else? does anyone have an example of how damage souce is used in a useful way? and also can you check the "damage type" of the damage source? (for those that don't know, damage type is NOT the same as attack type. attack types are Normal, Piercing, Siege, Magic, Hero, and Chaos, but damage types are Unknown, Normal, Enhanced, Fire, Cold, Lightning, Poison, Disease, Divine, Magic, Sonic, Acid, Force, Death, Mind, Plant, Defensive, Demolition, Slow Poison, Spirit Link, Shadow Strike, and Universal) so can you use these damage types as kind of elements and give each unit certain elemental weaknesses and strengths?

for example if i have a... i dont know... Lava Spawn unit that is clearly a fire creature, would there be a way to check if the damage that he takes is a fire type and if it is he only takes 50% of that damage, but if its a cold type attack he takes 150% of that damage?
 
Grundy said:
the data type "playercolor", how can that be used? can you use a playercolor variable for things such as: minimap ping colors (ping location action), game text color (display message to players), changing the color of a unit (making player 1's hero the blue color instead of red?), any other way to use this variable? or is it only used on conditions, like to check the color of a player?
The native SetUnitColor takes a playercolor argument, the ping minimap doesnt. Dont know if there are more uses of playercolor but it probebly is (is to lazy to look for more ways)

Grundy said:
also the event response Damage Source, obviously its the source of damage that a unit takes, but what exactly IS it? if i cast a spell on a unit is the damage source then the spell or the unit that cast the spell or something else? does anyone have an example of how damage souce is used in a useful way?
Damage Source is always the unit that made the damage, the caster, the attacker ect.

Grundy said:
and also can you check the "damage type" of the damage source? (for those that don't know, damage type is NOT the same as attack type. attack types are Normal, Piercing, Siege, Magic, Hero, and Chaos, but damage types are Unknown, Normal, Enhanced, Fire, Cold, Lightning, Poison, Disease, Divine, Magic, Sonic, Acid, Force, Death, Mind, Plant, Defensive, Demolition, Slow Poison, Spirit Link, Shadow Strike, and Universal) so can you use these damage types as kind of elements and give each unit certain elemental weaknesses and strengths?
You cannot get the damage type from a damage event. Blame blizzard.
 
Grundy said:
damn you blizzard.

so is damage type useful in anyway at all?

Yes they are. I dont think there is a need for all damage types. But if the type is magical, phisical or universal matters.

This is directly copied from vexorians caster system
Code:
Damage types: (how they act depends on tft magic things:
 - magical damage is buffed by etheral and resisted by spell immunes (normal spells)
 - phisical damage is resisted by ethereal and is able to affect spell immunes (passive spells)
 - Universal is buffed by ethereal and can even affect spell immunes (ultimates)

    DAMAGE_TYPE_FIRE                 Magical
    DAMAGE_TYPE_COLD                 Magical
    DAMAGE_TYPE_LIGHTNING            Magical
    DAMAGE_TYPE_DIVINE               Magical
    DAMAGE_TYPE_MAGIC                Magical
    DAMAGE_TYPE_SONIC                Magical
    DAMAGE_TYPE_FORCE                Magical
    DAMAGE_TYPE_DEATH                Magical
    DAMAGE_TYPE_MIND                 Magical
    DAMAGE_TYPE_PLANT                Magical
    DAMAGE_TYPE_DEFENSIVE            Magical
    DAMAGE_TYPE_SPIRIT_LINK          Magical
    DAMAGE_TYPE_SHADOW_STRIKE        Magical

    DAMAGE_TYPE_NORMAL               Phisical
    DAMAGE_TYPE_ENHANCED             Phisical
    DAMAGE_TYPE_POISON               Phisical
    DAMAGE_TYPE_DISEASE              Phisical
    DAMAGE_TYPE_ACID                 Phisical
    DAMAGE_TYPE_DEMOLITION           Phisical
    DAMAGE_TYPE_SLOW_POISON          Phisical

    DAMAGE_TYPE_UNKNOWN              Universal
    DAMAGE_TYPE_UNIVERSAL            Universal
 
ok so i just tried it, and you CAN have while loops without doing any different functions, infact EVERY "for" loop is a while loop. the for loops are really just while loops with the condition being some variable < than some number, and one of the loop actions incriments the number.

the thing i tested it with, i wanted a loop that will end when a unit dies

loop
exitwhen ( IsUnitAlive( gg_unig_nftt_0001 ) == false )
call DisplayTextToForce( GetAllPlayers(), "Unit is Alive" )
call TriggerSleepAction( 2 )
endloop

and i think there might be an error in vexorians description, i dont think shadow strike is magic damage because i have seen it damage units with magic immunity. the spell cannot be cast on them, but if it is cast on them when they are not immune and then they become immune the damage still hurts them
 
ok i dont know whats wrong with this line:
Code:
local rect spellarea = RectFromCenterSizeBJ( casterloc, range, range )

casterloc is a local location variable, and range is a local real variable.

i looked on http://jass.sourceforge.net/doc/api/common_j-types-rect.shtml and it says the RectFromCenterSizeBJ() function takes a loction, real, real. and that is what i passed to it. it also says that the function returns a rect. so i am trying to assign the rect that this function returns to my local rect variable named spellarea but its giving me this error message: "Type mismatch in assignment" anyone know whats wrong here?

---
edit: nevermind i got it... it was an error on the line BEFORE that. i wish it would have highlighted the line with the error not the line after it.
 
ok does anyone know whats wrong with this???

Code:
if ( GetBooleanAnd( (IsUnitAlly( GetEnumUnit(), tempPlayer )), ( IsUnitType( GetEnumUnit(), UNIT_TYPE_GIANT )) ) ) then

im getting "Expected a name"

i know IsUnitAlly( GetEnumUnit(), tempPlayer ) works
and i know IsUnitType( GetEnumUnit(), UNIT_TYPE_GIANT ) works
but i cannot get them to both work in an and.
 
The syntax in your code seems right, so it must work.
The only thing I can think is that there's no tempPlayer variable in scope.
Maybe it's defined local in some other function... dunno

Use AND instead of GetBooleanAnd
It's way better, faster, more readable and, after all, does the same.
 
i tried
Code:
if ( (IsUnitAlly( GetEnumUnit(), tempPlayer )) AND (IsUnitType( GetEnumUnit(), UNIT_TYPE_GIANT )) ) then
and that gave me different error, im not sure what it is im at school right now so i cant check, but that way didnt work so i tried the GetBooleanAnd function and it still didnt work.

i also tried
Code:
local unit tempUnit = GetEnumUnit()
if ( (IsUnitAlly( tempUnit, tempPlayer )) AND (IsUnitType( tempUnit, UNIT_TYPE_GIANT )) ) then

and that didnt work either.
changing it to 2 nested ifs worked but i want to know why this doesnt. there has to be some reason. i dont get it. i would rather do 1 if instead of nested ifs if i can get it to work.
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • V-SNES V-SNES:
    Happy Friday!
    +1
  • The Helper The Helper:
    we were down for a minute - think a log file or something got too big
    +1
  • Ghan Ghan:
    The alerts say it was down for a while unfortunately.
  • Ghan Ghan:
    Didn't know what was going on while I was at work.
  • Ghan Ghan:
    Disk filled up with logs. Fixed now.
    +1
  • The Helper The Helper:
    not a problem at all thanks for getting us back up
  • The Helper The Helper:
    I think the bots are finding a way to get through the anubis
  • The Helper The Helper:
    Happy Wednesday Everyone! Hope everyone has a Fantastic Day!
    +1
  • The Helper The Helper:
    Yeah, stats are showing big bot influx like 12k page views.
  • Wizard Wizard:
    :wave:
    +1
  • Ghan Ghan:
    TH changed his avatar again. 6 more weeks of summer.
    +3
  • Wizard Wizard:
    lol
    +1
  • The Helper The Helper:
    Guys just a heads up I am going to be shutting the site down soon. I am just waiting on the NUON people to decide whether they want to transfer forum data and keep the discord. My email is [email protected] for anyone that wants to keep in touch and I have a facebook too. I will make an official post later. Love you guys and will miss everyone!
    +1
  • V-SNES V-SNES:
    Sent a pm @The Helper
  • Stephen Stephen:
    Oh no - please don't lose the Nuon content
    +1
  • The Helper The Helper:
    Someone email AtariAge and see if they want me to transfer the forum data over to it
  • Ghan Ghan:
    Could probably keep NUON stuff around here if we wanted.
  • Ghan Ghan:
    Hmm what to do about the World Editor site though?
  • Stephen Stephen:
    I'd rather personally just own a backup of the Nuon data than see it go to AtariAge honestly. If it gets enshittified as per usual, or if some of the "regular" Jaguar folks get there, it's not gonna be fun
  • The Helper The Helper:
    There will be a github of the forum data so the NUON Forum Data I guess would be available there
  • The Helper The Helper:
    World Editor is technically Ryoko stuff not mine you guys can keep that I am not in that even
  • jonas jonas:
    :( end of an era :(
  • The Helper The Helper:
    Dont think of it as an end jonas - think of it as a beginning, because really my friend that is what it is.
  • A Andyoyo:
    Thank you for the hard work over the years. It did not go unnoticed.

The Helper Discord

Members online

No members online now.

Affiliates

Hive Workshop NUON Dome World Editor Tutorials
Back
Top