GetVariable from Plugin question

Posted by Erendir on Fri 17 Sep 2010 08:26 PM — 12 posts, 43,558 views.

Germany #0
The question may sound stupid, but i can't figure how to get a world variable from plugin inside?

What i do is:
1. Set variable `var` to `test` in the world properties-window
2. type `/print(GetVariable('var'))` in command input window (`/` is the script prefix)
I get `test` as expected
3. After that, i install some plugin with
<script>
<![CDATA[
Note(world.GetVariable('var'), GetVariable('var'))
]]>
</script>

4. The output i get is `nilnil`, and expected was `testnil` or `testtest`

So, what am i doing wrong?
USA #1
There is actually no difference between world.SomeFunction and SomeFunction. Without going into the details, the 'world' table is basically the default context of the script.

What you want is GetPluginVariable("", "var"). Using "" as the plugin ID for GetPluginVariable tells it to check the world instead.

[EDIT]: If you want to make it slightly more obvious, you can do this:
function GetWorldVariable(name)
  return GetPluginVariable("", name)
end

Note(GetWorldVariable("var"))

This doesn't change what happens, it just hides it behind a new function.
Amended on Fri 17 Sep 2010 08:30 PM by Twisol
Germany #2
Oh, that's great!
Thank You for such quick response!


Another question (don't want to start other topic yet):
can I get rid of VBscript, JScript etc. examples in the help? I'm interested only in Lua examples.
USA #3
No, the help files are entirely static. The examples are pretty similar in each language though; the difference is usually down to syntax. And some topics don't have Lua examples, if I remember correctly. It's not that big of a deal, in my experience. :)
Germany #4
It's just so that in just every topic i open in the help i usually scroll down to the Lua examples, and this is really annoying.
Germany #5
I knew, i seen here somewhere on the forum a possibility to customize the help!

It's here: http://gammon.com.au/forum/bbshowpost.php?id=8973

The question now is only "how to compile this docgen???"
USA #6
Well, keep in mind: if you compile your own set of help files, you'll have to edit and recompile it every time Nick releases a new version with documentation changes.

Go to your start menu and look for an HTML Help Workshop folder. I think it comes with Windows by default, but frankly I'm not entirely sure. That's what you'd use to compile the help docs.
Germany #7
i do have the "Microsoft Help Workshop" (just got somewhere), but i have no idea how to compile the docgen from the source (downloaded from the first link in the http://gammon.com.au/forum/bbshowpost.php?id=8973 topic)
Australia Forum Administrator #8
Erendir said:

I'm interested only in Lua examples.



He has a point. In version 4.62 I revamped the order so that Lua comes first (and the return codes next). I agree you usually have to scroll down to find the stuff you really want.

As an example of how it will look, I re-did the online version, so check this out:

http://www.gammon.com.au/scripts/doc.php?function=ColourNote
Germany #9
Exactly what i mean!

Maybe - i'm not sure - `Return value` before `Lua example` would be better.
USA #10
Ahh, good idea Nick!

I agree, moving the return value section to before the examples would be a lot better.
Australia Forum Administrator #11
Check it out now.