cant't use "else"

Runes of Magic/Radiant Arcana (http://www.runesofmagic.com)
Post Reply
Message
Author
Baerxu
Posts: 11
Joined: Thu Oct 31, 2013 1:22 pm

cant't use "else"

#1 Post by Baerxu » Wed Nov 06, 2013 3:56 am

Hey there,

I want to make bot which will choose his equip from quests depending on his class.

The first pieces of equipment are obtained in from a armorbag and a weaponbag. So I let my bot open those bags. Now it shall check which class the bot's primary class is because the equipment u get from those bags are class-dependant, e.g. a mage gets a wand, a rouge gets a dagger.

Code: Select all

	inventory:update();
		inventory:useItem(201704); -- Waffen-Paket
		inventory:useItem(201705); -- Ruestungspaket

		if (player.Class1 == CLASS_SCOUT or player.Class1 == CLASS_ROGUE) then
			inventory:useItem(210512);
			inventory:useItem(221582);
		else if (player.Class1 == CLASS_MAGE or player.Class1 == CLASS_PRIEST) then
			inventory:useItem(210514);
			inventory:useItem(221584);
		else
			inventory:useItem(210511‎);
			inventory:useItem(221582);
		end;

		inventory:useItem(209577); -- Geheimnisvolle Runenschriftrolle 
Alright, the problem with this is: it doesn't work. Well acutally it does work but the 'else' ruins it. Let me explain:
Whenever I try to run this mm keeps telling my I got a compilationerror and I should check the LUA code there. As I couldn't find any mistake just from looking at it, I did some tests.

Code: Select all

		if (player.Class1 == CLASS_SCOUT or player.Class1 == CLASS_ROGUE) then
			inventory:useItem(210512);
			inventory:useItem(221582);
Using this piece of Code only works perfectly fine. He opens the bags, equips everything and uses the runic scroll.

It's the same with this piece of code:

Code: Select all

if (player.Class1 == CLASS_MAGE or player.Class1 == CLASS_PRIEST) then
			inventory:useItem(210514);
			inventory:useItem(221584);
And now comes the big problem: If I use something like

Code: Select all

		if (player.Class1 == CLASS_MAGE or player.Class1 == CLASS_PRIEST) then
			inventory:useItem(210514);
			inventory:useItem(221584);
		else
			inventory:useItem(210511‎);
			inventory:useItem(221582);
		end;
I keep getting this compilation error.
I've tested this stuff in nearly every possible combination but whenever it comes to "else" my script goes bananas. The weird thing is that I am using "else" in many other WPs and they work fine. So what's the problem with this particular piece of code? What am I missing?

btw.
1. I know those Items arent completely right.. But as long as I can't get it to work, I don't care.
2. I am using the newest version of mm.

Thanks in advance :*

User avatar
Bill D Cat
Posts: 555
Joined: Sat Aug 10, 2013 8:13 pm
Location: Deep in the Heart of Texas

Re: cant't use "else"

#2 Post by Bill D Cat » Wed Nov 06, 2013 4:54 am

Baerxu wrote:Hey there,

I want to make bot which will choose his equip from quests depending on his class.

The first pieces of equipment are obtained in from a armorbag and a weaponbag. So I let my bot open those bags. Now it shall check which class the bot's primary class is because the equipment u get from those bags are class-dependant, e.g. a mage gets a wand, a rouge gets a dagger.

Code: Select all

	inventory:update();
		inventory:useItem(201704); -- Waffen-Paket
		inventory:useItem(201705); -- Ruestungspaket

		if (player.Class1 == CLASS_SCOUT or player.Class1 == CLASS_ROGUE) then
			inventory:useItem(210512);
			inventory:useItem(221582);
		else if (player.Class1 == CLASS_MAGE or player.Class1 == CLASS_PRIEST) then
			inventory:useItem(210514);
			inventory:useItem(221584);
		else
			inventory:useItem(210511‎);
			inventory:useItem(221582);
		end;

		inventory:useItem(209577); -- Geheimnisvolle Runenschriftrolle 
In this block of code, you are missing an "end" statement. Let me reformat it a little and you'll see why.

Code: Select all

		if (player.Class1 == CLASS_SCOUT or player.Class1 == CLASS_ROGUE) then
			inventory:useItem(210512);
			inventory:useItem(221582);
		else
			if (player.Class1 == CLASS_MAGE or player.Class1 == CLASS_PRIEST) then
				inventory:useItem(210514);
				inventory:useItem(221584);
			else
				inventory:useItem(210511‎);
				inventory:useItem(221582);
			end;
				<-- Missing "end" here.
		inventory:useItem(209577); -- Geheimnisvolle Runenschriftrolle 
Now if you just changed the "else if" to remove the space and make it "elseif" then everything should work fine.

Baerxu
Posts: 11
Joined: Thu Oct 31, 2013 1:22 pm

Re: cant't use "else"

#3 Post by Baerxu » Wed Nov 06, 2013 5:46 am

Thanks, that really was helpful but my problem still remains.

I changed my script a little to make it easier for me to use in future waypoints... So in my onload event I integrated this in my onload-event:

Code: Select all

		if (player.Class1 == 2 or player.Class1 == 3) then
			_armor = 0;
		else
			if (player.Class1 == 4 or player.Class1 == 5 or player.Class1 == 8) then
				_armor = 1;
			else
				if player.Class1 == 1 then
					_armor = 2;
				else 
					_armor = 3;
				end
			end
		end
Since I added those both "end"s I don't receive an onload error anymore - which I received before when I was trying to fix and change this stuff myself - so it seems to me it's working fine.
But in the WP itself it still doesn't work.

Code: Select all

		if _armor == 0 then -- Leather
			inventory:useItem(210512);
			inventory:useItem(221582);
		else if _armor == 1 then -- Cloth
				inventory:useItem(210514);
				inventory:useItem(221584);
			else if _armor == 2 then -- Warrior
					inventory:useItem(210511‎);
					inventory:useItem(221582);
				else -- Knight
					inventory:useItem(210511‎);
					inventory:useItem(221582);
				end
			end
		end
Actually there should be enough "end"s as there are as many "end"s as "if"s and it's working this way in the onload-event (at least I don't receive a error message).

There is no difference concerning the compilation-error I receive whether I use "else if" or "elseif"... Btw does that matter?

User avatar
rock5
Posts: 12173
Joined: Tue Jan 05, 2010 3:30 am
Location: Australia

Re: cant't use "else"

#4 Post by rock5 » Wed Nov 06, 2013 6:05 am

Let me see if I can explain it so you can understand.

Code: Select all

if A then
    -- do A stuff
elseif B then
    -- do B stuff
elseif C then
    -- do C stuff
end
What this means is if A is true then it does A stuff. If it's false and B is true then it does B stuff. If A and B are false and C is true then it does C stuff.

Code: Select all

if A then
    -- do A stuff
else
    if B then
        -- do B stuff
    else
        if C then
            -- do C stuff
        end
    end
end
Actually, functionally, these would work the same. The difference being that the first example is a lot easier to understand, it's just 1 of 3 possible values, and the second could become very complicated very fast. I guess you could consider elseif a way of simplifying else ifs.
  • Please consider making a small donation to me to support my continued contributions to the bot and this forum. Thank you. Donate
  • I check all posts before reading PMs. So if you want a fast reply, don't PM me but post a topic instead. PM me for private or personal topics only.
  • How to: copy and paste in micromacro
    ________________________
    Quote:
    • “They say hard work never hurt anybody, but I figure, why take the chance.”
          • Ronald Reagan

Baerxu
Posts: 11
Joined: Thu Oct 31, 2013 1:22 pm

Re: cant't use "else"

#5 Post by Baerxu » Wed Nov 06, 2013 6:18 am

Alright, thanks for this explanation, I guess I'll stick with elseif then (:
So I took this piece of code

Code: Select all

if A then
    -- do A stuff
elseif B then
    -- do B stuff
elseif C then
    -- do C stuff
end
And made my piece of code look alike

Code: Select all

		if _armor == 0 then -- A
			inventory:useItem(210512); -- A Stuff
			inventory:useItem(221582);
		elseif _armor == 1 then  -- B
			inventory:useItem(210514); -- B Stuff
			inventory:useItem(221584);
		elseif _armor == 2 then  -- C
			inventory:useItem(210511‎); -- C Stuff
			inventory:useItem(221582);
		elseif _armor == 3 then  -- D
			inventory:useItem(210511‎); --D Stuff
			inventory:useItem(221582);
		end
I still receive "Failed to compile and run LUA Code [...]".
Everything else in this WP is working fine. In case I start the script without this if-check everything runs smoothly.

User avatar
rock5
Posts: 12173
Joined: Tue Jan 05, 2010 3:30 am
Location: Australia

Re: cant't use "else"

#6 Post by rock5 » Wed Nov 06, 2013 6:31 am

I can't see anything wrong with that code but I copied it to my editor to see if the syntax highlighting would point anything out. In the editor I noticed that the 2 (210511)s had a question mark after them, before the brack. It's not visible in this post but I'm assuming they are some sort of hidden character. Try typing those numbers again including the brackets and see if that help.
  • Please consider making a small donation to me to support my continued contributions to the bot and this forum. Thank you. Donate
  • I check all posts before reading PMs. So if you want a fast reply, don't PM me but post a topic instead. PM me for private or personal topics only.
  • How to: copy and paste in micromacro
    ________________________
    Quote:
    • “They say hard work never hurt anybody, but I figure, why take the chance.”
          • Ronald Reagan

Baerxu
Posts: 11
Joined: Thu Oct 31, 2013 1:22 pm

Re: cant't use "else"

#7 Post by Baerxu » Wed Nov 06, 2013 6:43 am

OMG, I am so damn angry right now. I have been trying to fix this piece of code for hours! Tryed every possibility I could think of... And it turns out that an **** invisible ? is ruining my code -.-
Anyways, thaaaaanks a lot. (:

User avatar
Bill D Cat
Posts: 555
Joined: Sat Aug 10, 2013 8:13 pm
Location: Deep in the Heart of Texas

Re: cant't use "else"

#8 Post by Bill D Cat » Thu Nov 07, 2013 12:02 am

Baerxu wrote:Thanks, that really was helpful but my problem still remains.

I changed my script a little to make it easier for me to use in future waypoints... So in my onload event I integrated this in my onload-event:

Code: Select all

		if (player.Class1 == 2 or player.Class1 == 3) then
			_armor = 0;
		else
			if (player.Class1 == 4 or player.Class1 == 5 or player.Class1 == 8) then
				_armor = 1;
			else
				if player.Class1 == 1 then
					_armor = 2;
				else 
					_armor = 3;
				end
			end
		end
Just wanted to say "Aw, no love for the dwarves?" player.Class1 will be either 9 or 10 for Warlock or Champion.
And a suggestion for easier debugging of the code later, you could use the class names instead of the numbers like this:

Code: Select all

		if (player.Class1 == CLASS_SCOUT or player.Class1 == CLASS_ROGUE) then
			_armor = 0;
		elseif (player.Class1 == CLASS_MAGE or player.Class1 == CLASS_PRIEST or player.Class1 == CLASS_DRUID or player.Class1 == CLASS_WARLOCK) then
			_armor = 1;
		elseif (player.Class1 == CLASS_WARRIOR or player.Class1 == CLASS_CHAMPION) then
			_armor = 2;
		else 
			_armor = 3;
		end
Though I suppose with some elite skills, those values may change. ie: Warrior/Knight and Warden/Warrior get plate armor with their level 40 elites, and I think I read that the Druid/Warrior gets an upgrade as well to use chain armor with their level 70 elite. (But still no love from Runewaker for the Battle Monk!!)

Baerxu
Posts: 11
Joined: Thu Oct 31, 2013 1:22 pm

Re: cant't use "else"

#9 Post by Baerxu » Thu Nov 07, 2013 5:23 am

I've added the dwarf-classes by now, don't worry :b

Ye, those might change but as this is a script for a starting area this far, there is no chance any plate items will be distributed.
As soon as they may get plate armor as a questreward, I might check for those elite-skills but right now there is no need to do this. Anyways thanks for that hint (:

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot], Google [Bot] and 1 guest