Jump to content
The Indie Stone Forums
Okamikurainya

How to find value of a variable?

Recommended Posts

Hey all!

Hopefully someone can help me out here, I'm trying to figure out exactly how the world's name is stored.
Specifically so I can use it for world based scripting.

Here's a simple example:

 

function WhichWorld()

	local where = getWorld();
	local player = getSpecificPlayer(0);

		if where == "Madhbih Oasis" then --Name of the map's Lots
			player:Say("I am in the desert.");
		else
			player:Say("I have no idea where I am.");
			end
	end
	
Events.EveryHours.Add(WhichWorld);

 

The name of the Lots isn't working and trying to print the variable throws up errors. Where am I going wrong and what direction can I take to get on the right path?

Share this post


Link to post
Share on other sites

Didn't look to closely into this, but getWorld() gives you an Instance of IsoWorld, so you can't directly deprive the name of it. There is the method getWorld() inside IsoWorld, so maybe it does work if you rewrite your example code to something like this:

function WhichWorld()

	local where = getWorld();
	local player = getSpecificPlayer(0);

		if where.getWorld() == "Madhbih Oasis" then --Name of the map's Lots
			player:Say("I am in the desert.");
		else
			player:Say("I have no idea where I am.");
			end
	end
	
Events.EveryHours.Add(WhichWorld);

Notice the getWorld() that I added to your where in the if statement.

Share this post


Link to post
Share on other sites

Still no luck, but thanks! That throws up "java.lang.RuntimeException: getWorld: Expected a method call but got a function call."

What about a way to set a global variable? I could set it to false on game start, but set it to true in the spawnpoints.lua. :huh:

Share this post


Link to post
Share on other sites
16 hours ago, Dr_Cox1911 said:

(snip)


I cracked it!

the correct way to do it is:

function WhichWorld()

	local player = getSpecificPlayer(0);
	local where = getWorld():getMap();

		if where == "Madhbih Oasis" then --Name of the map's Lots
			player:Say("I am in the desert.");
		else
			player:Say("I have no idea where I am.");
			end
	end
	
Events.EveryHours.Add(WhichWorld);

This opens up so many possibilities... Map based loot tables, individual map climates... Woo! :lol:

Edited by Okamikurainya

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...