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.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top