Roll20 uses cookies to improve your experience on our site. Cookies enable you to enjoy certain features, social sharing functionality, and tailor message and display ads to your interests on our site and others. They also help us understand how our site is being used. By continuing to use our site, you consent to our use of cookies. Update your cookie preferences .
×
Create a free account

[Programming]

var malikai = malikai || {}; I am pretty sure I am misunderstanding it. Var [name] = [name] or {object}
Crap, I am an idiot, I meant to finish the TITLE, DAMNIT.
1376858022
Gauss
Forum Champion
Could you clarify the purpose of this post? Im not sure I see a question here.  - Gauss
1376872161

Edited 1376872816
Fuck, that is what I get for posting when I am so tired. Long day. ... var malikai = malikai || {}; var varname = varname || {}; What does this mean? I am pretty sure I am misunderstanding it. Var [name] = [name] or {object}
Also, thanks for responding. It means a lot. I don't know what this is called, and I googled the syntax, but got no relevant results. I was creating a custom character sheet generator, based off of a currently posted one, and I didn't know what that part meant. (Being a fundamental part of the generator, I want to know what it means.)
1376873820
Gauss
Forum Champion
I am confused, where are you seeing this? In the console? - Gauss
1376876941

Edited 1376876965
In the script itself. So here  is the original.  I was curious what var malikai = malikai || {} did.
1376877276

Edited 1376877354
It means this: If malikai already exists, it sets malikai to malikai, or in other words, it doesn't change it. If malikai does not already exist, it uses the second part of the OR and creates the variable and sets it with an empty object. That is used because all API scripts in a campaign share the same global variables. So if script A sets the variable "a" to "Hello" and script B then does a log(a) without setting "a" first, it prints "Hello". Or if B changes the variable, it also changes for the other script and so on. So this line is basically made to be sure that global variables of one script don't overwrite the ones in another, if they happen to use the same name.
1376879380
Gauss
Forum Champion
Oh, you are talking about API scripts. You didn't specify to begin with. :) I am moving this to the API forum. - Gauss
1376887225
Lithl
Pro
Sheet Author
API Scripter
The line is used to create namespaces for scripts. The || syntax is used to make sure the namespace isn't overridden if it already exists, or creates the "namespace" object if it doesn't already exist. Once the namespace object is available, you can simply put all of your variables and functions into that object, and they won't collide with other scripts in your campaign. Now you can have malakai.foo and iakalam.foo as different variables.
1376916572

Edited 1376916598
Thanks Brian and Quatar! And sorry for the headache Gauss!