How to find value of a variable?
1 1

4 posts in this topic

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
1 1