Using spaces in JASS matter?

Mr.Tutorial

Hard in the Paint.
Reaction score
42
I've noticed in some peoples triggers their is JASS and it has spaced out (For example):

JASS:
blah blah blah blah
              blah
                 blah blah blah
              blah
    blah blah blah...


Stuff like that...

MY QUESTION Are spaces needed when writing a jass script?
 

Rheias

New Helper (I got over 2000 posts)
Reaction score
232
Needed? No.
However, it makes the reading process much easier.
If you are ever planning to learn Jass I urge you to use spaces.
 

~GaLs~

† Ғσſ ŧħə ѕαĸε Φƒ ~Ğ䣚~ †
Reaction score
180
>>Are spaces needed when writing a jass script?
It is use to indent the code. Make it more readable.
 

Matemeo

New Member
Reaction score
20
Some people, myself included get very easily lost when its a huge block of code, indetting blocks helps to 1. Follow the structure and logic of the code, and 2. Break it up into easier to read chunks.

Some people don't have a problem with non-indentation, but a lot of people prefer indentation.

JASS:

function blahdeblah takes nothing returns String
   local unit sweetMonster = GetTriggerUnit()
   
   if sweetMonster.getCalories() > 5000 then
      return "Wow, your fat"
   else
      return "Not too fat"
   endif

   set sweetMonster = null
endfunction


That is how I indent for the most part, personal preference when it comes to indentation, find something that works for you, and hopefully, it'll work for everyone who reads it :p
 

ReVolver

Mega Super Ultra Cool Member
Reaction score
609
It's like writing a paragraph, people like to read something that has proper indexation rather than a sloppy paper.

And for JASS, it's easier to read/find and to fix any problems.
 

PurgeandFire

zxcvmkgdfg
Reaction score
509
If you are making a protected map, make the spaces as crappy as possible or if it is an unprotected map that you want people not to understand your codes. Just in case people might deprotect it or extract the .j. Otherwise, just use Vexorian's optimizer. Dr. Super Good can still read vex's code and he can deprotect it but it is the best way. :p

If it is going to be posted somewhere, indent properly. Stuff like this, doesn't matter:
JASS:
    call RemoveLocation (udg_Fart)
    call RemoveLocation(udg_Fart)
//Same thing

JASS:
call RemoveLocation(udg_Fart)
    call RemoveLocation(udg_Fart)
//Same thing

JASS:
    call CreateUnit(id       , 'halo',x     ,   y  ,  270)
    call CreateUnit(id,'halo',x,y,270)
//Same thing


Just make sure everything is spelled correctly and that the capitalization is correct (obviously, JASS is case sensative.)
 

Sim

Forum Administrator
Staff member
Reaction score
534
> Using spaces in JASS matter?

> MY QUESTION: Are spaces needed when writing a jass script?

Those are 2 different questions :p

It does matter, but it isn't "needed".
 

Silvenon

New Member
Reaction score
19
I always leave an empty line before and after loops, ifs etc. It's easier to read.

For capitalization/spelling problems there are jass editors, like JassCraft, that highlights (and indents, which saves you time) functions, constants, certain keywords etc. so it's easier to code because if you spelled it right, it gets highlighted, if not............then it doesn't :)

Btw:

JASS:
call RemoveLocation(udg_Loc)
call Remo ve     Loca    tion(udg_Loc)
// NOT THE SAME!!!


JASS:
call RemoveLocation(udg_Loc)
call RemoveLocation(ud  g_L  oc)
// NOT THE SAME!!!


I think you get the point :)
 

N-a-z-g-u-l

New Member
Reaction score
30
if you are too lazy to add spaces while typing new code, finish it and afterwars feed this program with it :p

http://mariusb.kilu.de/jassformat.htm

i made this program because i am creating a map together with another mapper and he does not add spaces correctly, sometimes use spaces and sometimes tabs... it was way less work to make this program instead of going through the whole code and do it by hand


this example shows that spaces increase readability clearly^^

JASS:
globals
integer array udg_AV_Handles
endglobals

function H2I takes handle h returns integer
return h
return 0
endfunction

function NewHandleId takes handle h returns integer
local integer EnumId
local integer ConvertedHandle=H2I(h)
local integer StartId=ConvertedHandle-(ConvertedHandle/8192)*8192
if StartId < 0 then
set StartId=StartId + 8192
endif
set EnumId=StartId
loop
if udg_AV_Handles[EnumId] == 0 then
set udg_AV_Handles[EnumId]=ConvertedHandle
return EnumId
elseif EnumId < 8191 then
set EnumId=EnumId + 1
else
set EnumId=0
endif
exitwhen EnumId == StartId
endloop
return -1
endfunction

function GetHandleId takes handle h returns integer
local integer EnumId
local integer ConvertedHandle=H2I(h)
local integer StartId=ConvertedHandle-(ConvertedHandle/8192)*8192
if StartId < 0 then
set StartId=StartId + 8192
endif
set EnumId=StartId
loop
if udg_AV_Handles[EnumId] == ConvertedHandle then
return EnumId
elseif EnumId < 8191 then
set EnumId=EnumId + 1
else
set EnumId=0
endif
exitwhen EnumId == StartId
endloop
return NewHandleId(h)
endfunction

function ClearHandleId takes integer Id returns nothing
set udg_AV_Handles[Id]=0
endfunction
will become

JASS:
globals
	integer array udg_AV_Handles
endglobals

function H2I takes handle h returns integer
	return h
	return 0
endfunction

function NewHandleId takes handle h returns integer
	local integer EnumId
	local integer ConvertedHandle=H2I(h)
	local integer StartId=ConvertedHandle-(ConvertedHandle/8192)*8192
	if StartId < 0 then
		set StartId=StartId + 8192
	endif
	set EnumId=StartId
	loop
		if udg_AV_Handles[EnumId] == 0 then
			set udg_AV_Handles[EnumId]=ConvertedHandle
			return EnumId
		elseif EnumId < 8191 then
			set EnumId=EnumId + 1
		else
			set EnumId=0
		endif
		exitwhen EnumId == StartId
	endloop
	return -1
endfunction

function GetHandleId takes handle h returns integer
	local integer EnumId
	local integer ConvertedHandle=H2I(h)
	local integer StartId=ConvertedHandle-(ConvertedHandle/8192)*8192
	if StartId < 0 then
		set StartId=StartId + 8192
	endif
	set EnumId=StartId
	loop
		if udg_AV_Handles[EnumId] == ConvertedHandle then
			return EnumId
		elseif EnumId < 8191 then
			set EnumId=EnumId + 1
		else
			set EnumId=0
		endif
		exitwhen EnumId == StartId
	endloop
	return NewHandleId(h)
endfunction

function ClearHandleId takes integer Id returns nothing
	set udg_AV_Handles[Id]=0
endfunction
 

Matemeo

New Member
Reaction score
20
if you are too lazy to add spaces while typing new code, finish it and afterwars feed this program with it :p

http://mariusb.kilu.de/jassformat.htm

i made this program because i am creating a map together with another mapper and he does not add spaces correctly, sometimes use spaces and sometimes tabs... it was way less work to make this program instead of going through the whole code and do it by hand


this example shows that spaces increase readability clearly^^

JASS:
globals
integer array udg_AV_Handles
endglobals

function H2I takes handle h returns integer
return h
return 0
endfunction

function NewHandleId takes handle h returns integer
local integer EnumId
local integer ConvertedHandle=H2I(h)
local integer StartId=ConvertedHandle-(ConvertedHandle/8192)*8192
if StartId < 0 then
set StartId=StartId + 8192
endif
set EnumId=StartId
loop
if udg_AV_Handles[EnumId] == 0 then
set udg_AV_Handles[EnumId]=ConvertedHandle
return EnumId
elseif EnumId < 8191 then
set EnumId=EnumId + 1
else
set EnumId=0
endif
exitwhen EnumId == StartId
endloop
return -1
endfunction

function GetHandleId takes handle h returns integer
local integer EnumId
local integer ConvertedHandle=H2I(h)
local integer StartId=ConvertedHandle-(ConvertedHandle/8192)*8192
if StartId < 0 then
set StartId=StartId + 8192
endif
set EnumId=StartId
loop
if udg_AV_Handles[EnumId] == ConvertedHandle then
return EnumId
elseif EnumId < 8191 then
set EnumId=EnumId + 1
else
set EnumId=0
endif
exitwhen EnumId == StartId
endloop
return NewHandleId(h)
endfunction

function ClearHandleId takes integer Id returns nothing
set udg_AV_Handles[Id]=0
endfunction
will become

JASS:
globals
	integer array udg_AV_Handles
endglobals

function H2I takes handle h returns integer
	return h
	return 0
endfunction

function NewHandleId takes handle h returns integer
	local integer EnumId
	local integer ConvertedHandle=H2I(h)
	local integer StartId=ConvertedHandle-(ConvertedHandle/8192)*8192
	if StartId < 0 then
		set StartId=StartId + 8192
	endif
	set EnumId=StartId
	loop
		if udg_AV_Handles[EnumId] == 0 then
			set udg_AV_Handles[EnumId]=ConvertedHandle
			return EnumId
		elseif EnumId < 8191 then
			set EnumId=EnumId + 1
		else
			set EnumId=0
		endif
		exitwhen EnumId == StartId
	endloop
	return -1
endfunction

function GetHandleId takes handle h returns integer
	local integer EnumId
	local integer ConvertedHandle=H2I(h)
	local integer StartId=ConvertedHandle-(ConvertedHandle/8192)*8192
	if StartId < 0 then
		set StartId=StartId + 8192
	endif
	set EnumId=StartId
	loop
		if udg_AV_Handles[EnumId] == ConvertedHandle then
			return EnumId
		elseif EnumId < 8191 then
			set EnumId=EnumId + 1
		else
			set EnumId=0
		endif
		exitwhen EnumId == StartId
	endloop
	return NewHandleId(h)
endfunction

function ClearHandleId takes integer Id returns nothing
	set udg_AV_Handles[Id]=0
endfunction


Wow...Every trigger that is public should be ran through that, as long as it works perfectly, thats frikkin sweet. :p
 

N-a-z-g-u-l

New Member
Reaction score
30
i had no problems with the script till now, and when creating it, i was some kind surprised that it was so easy to do, so i doubt there will be heavy errors... but nontheless, you can notify me if you find some ;)

and by the way, +rep is always a good thing :p


but this is going offtopic

i recommend using tabs to structure the code (possible with TESH, the WE trigger editor field does not accept tabs except of from STRG+V), and leave spaces before and after =, ==, <, >, and so on... also, arguments are a bit clearer if you place a space after each comma
i also thought about implementing this into the jass formatter, but for long scripts that would be laggy
 

Silvenon

New Member
Reaction score
19
But people like Vex and other hardcore jassers indent code like this:

JASS:
call Something(p1,p2,r,t,100,&quot;kl&quot;)
if GetUnitUserData(u)==1 then
    call DoSomething()
endif

    call DoSomethingElse()
// ....


With no spacings after commas in parameters and no spacings before and after limitops (==, <, >,...). I find that rather ugly....
 

N-a-z-g-u-l

New Member
Reaction score
30
yes, i dont know how thats good either... and those short variable names of about 2 letters^^

i name variables self-explanatory, too...

only for systems i upload, i try to get every bit of performance i can get (with short names and so on), and the code also is smaller then... ive heard that its quite a lot (somebody reasoned differences in a benchmark with it)

i like code with spaces more, perhaps i will add those to the script, too :) then you can just put every code you find on the internet into this program, format it and then read it^^
 

Silvenon

New Member
Reaction score
19
Name your variables with 1-2 letters, 3 (or more) is too many.

For example:

JASS:
function Trig_Spell_Actions takes nothing returns nothing
    local unit c = GetTriggerUnit() // Caster
    local unit t = GetSpellTargetUnit() // Target
    // ...
endfunction


Don't name your locals like this:

JASS:
function Trig_Spell_Actions takes nothing returns nothing
    local unit SpellCaster = GetTriggerUnit()
    local unit SpellTargetUnit = GetSpellTargetUnit()
    // ...
endfunction


You'll soon realize why. It's just too much to type and it eats time. Naming your locals like that is a sign of GUI > JASS transfer. If you want to make a function for others, for example SetLightningToRed, name your variables (parameters, in this case) like this:

JASS:
function SetLightningToRed takes lightning whichLightning, real density returns nothing
    // ...
endfunction


That's the way parameters are named if meant to be viewed by others, if you still don't understand the naming method, just take a look at some BJs or natives in JassCraft or some other jass editor.
 

AceHart

Your Friendly Neighborhood Admin
Reaction score
1,495
> That's the way parameters are named if meant to be viewed by others

Basically, you make it easy for others, and unreadable crap for yourself?
Cool... yes, I can really see the use there...
 

Vexorian

Why no custom sig?
Reaction score
187
But people like Vex and other hardcore jassers indent code like this:

JASS:
call Something(p1,p2,r,t,100,&quot;kl&quot;)
if GetUnitUserData(u)==1 then
    call DoSomething()
endif

    call DoSomethingElse()
// ....


With no spacings after commas in parameters and no spacings before and after limitops (==, <, >,...). I find that rather ugly....

I only add spaces when that actually makes it easier to read...

JASS:

     call UnitAddAbility(u,a)


vs.
JASS:
     call UnitAddAbility(u    ,   a)


Too much spaces.


Instead:

JASS:

     call SetAbilityDataReal(&#039;A000&#039;,&quot;damage&quot;,2.5)
     call SetAbilityDataReal(&#039;A000&#039;,&quot;delay&quot;,7.8)



vs.

JASS:

     call SetAbilityDataReal(&#039;A000&#039;,&quot;damage&quot;,2.5)
     call SetAbilityDataReal(&#039;A000&#039;,&quot;delay&quot; ,7.8)


Good to use spaces.

Regarding local variable names, there are two kind of local variables, the ones that are boringly common and the ones that are not common, it is a good idea to use short names for these common usage locals, and most importantly, always use the same names. The other ones do need explanatory names, but notice that when a variable's name is too long it is as bad as a short name.

JASS:

local unit u=GetTriggerUnit() //I mean, seriously if you always use u for GetTriggerUnit or &quot;the main unit&quot; it will be both short and consistent...


JASS:

local unit attacker = GetAttacker() //this is good if in that specific function there are many roles for plenty of units


JASS:

local unit unitattackingthecasterafter2secondsoftime //nocomment...


JASS:

local integer i=0 //integers i,j,k are often used as loop counters, and are fairly common, if instead you called those counter variables &quot;counter&quot; it would be lame.



JASS:

local string k


I think this is a bad standard name, even though I used it plenty of times, in the old gamecache times there were needs for gamecache keys and I used string k for it, but it conflicts for one of those assigned for counters, and it doesn't look easy to understand.

JASS:

local gamecache g

This used to be soo necessary, and using a long name there would quite kill your patience, it is a good thing that vJass introduced global declarations so we could use cs_cache or something like that there... without declaring any local.

...
Globals are another story, they should always have good names, and a prefix from where they come from. Scopes make the deal with globals much cleaner than before.

A private global can have such a silly short name like V , V and M are other good short names in my opinion since they represent Vectors or Matrixes, in fact, I for some reason always use capital letters to represent these ents, in a bignum library I made the other day I used bignum A , bignum B...
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +2
  • V-SNES V-SNES:
    Happy Friday!
    +1
  • The Helper The Helper:
    New recipe is another summer dessert Berry and Peach Cheesecake - https://www.thehelper.net/threads/recipe-berry-and-peach-cheesecake.194169/

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top