[vJass] Global Variables Question

tooltiperror

Super Moderator
Reaction score
231
Let's say I declared these variables.

JASS:

globals
    string a = cheese
    string b = stringy
endglobals


And I created this function:

JASS:

function stringcheese takes nothing returns nothing
    call BJDebugMsg(b+" "a)
endfunction


Would it display "string cheese" or do I need to add in a prefix to symbolize globals or something, or will it just know they are globals in vJass? (Unless overwritten in the trigger, of course.)

I would just do it myself to test, but I'm on a mac, so I can't do vJass at the moment.

Random Thing: Would I need to return a string when using [ljass]BJDebugMsg[/ljass]?
 

kingkingyyk3

Visitor (Welcome to the Jungle, Baby!)
Reaction score
216
No need to put " " for string variables.

JASS:
call BJDebugMsg("Meh")


or

JASS:
globals
    string hehe = "Meh"
endglobals

call BJDebugMsg(hehe)


They both display "Meh".

Would I need to return a string when using BJDebugMsg?
Huh?
function BJDebugMsg takes string s returns nothing
Nothing returns from it.
 

tooltiperror

Super Moderator
Reaction score
231
The Quotes were for a space, actually. There was a space between them.

Anyway, thanks for the help. But I didn't know it takes a string, but I guess that's because it takes a global.

Thanks, and your avatar is cool, and happy thanksgiving to you and your family.
 

millz-

New Member
Reaction score
25
Your BJDebugMsg may not work if cheese and stringy are not variables, because in that case, you are setting the variable cheese into a and the variable stringy into b. If you wanted "cheese" to be stored in a and "stringy" to be stored in b instead, you need to add the quotes, e.g.:

JASS:
globals
    string a = "cheese"
    string b = "stringy"
endglobals


Then in this case,

JASS:

call BJDebugMsg(b+" "+a)

would display "stringy cheese".
 

tooltiperror

Super Moderator
Reaction score
231
My bad, forgot the quotes!

Happy Thanksgiving.
 

Romek

Super Moderator
Reaction score
963
No prefixes are required for globals, locals, arguments, constants, etc.
For this reason, amongst others, we have naming conventions.

Global constants should be named with ALL_CAPITALS.
Globals should be have a capital letter at the start of each 'word'.
Locals should be in all-small letters.
Arguments should be in camelCase.

Not only does this improve the readability of code (you know what something is without having to check), but it also decreases the chances of having two things with the same name.
 

tooltiperror

Super Moderator
Reaction score
231
But if I create a string with a '|' in it, how do I do capitalization or something?
 

Romek

Super Moderator
Reaction score
963
Those were for the variable names themselves, and have nothing to do with the values the variables contain.

You can only use alphanumeric characters (and '_') when naming stuff, and the name must start with a letter.
 

tooltiperror

Super Moderator
Reaction score
231
Oh, I thought you meant the value, not the name. Editing that now in the code I'm developing. Thanks, Romek!
 

Narks

Vastly intelligent whale-like being from the stars
Reaction score
90
No prefixes are required for globals, locals, arguments, constants, etc.
For this reason, amongst others, we have naming conventions.

Global constants should be named with ALL_CAPITALS.
Globals should be have a capital letter at the start of each 'word'.
Locals should be in all-small letters.
Arguments should be in camelCase.

Not only does this improve the readability of code (you know what something is without having to check), but it also decreases the chances of having two things with the same name.

why isn't this in sticky?
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      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