Page 1 of 1

Local counter

Posted: Wed Oct 24, 2012 3:53 am
by ZZZZZ
Hello,

Im just trying to figure out how to increment a counter.
eg

Code: Select all

<onLoad>
	local count1 = RoMScript("Daily_count()");
</onLoad>	
        <!-- #  1 --><waypoint x="-20796" z="-22649" y="591">	</waypoint>
	<!-- #  2 --><waypoint x="-21125" z="-22420" y="618">	</waypoint>
	<!-- #  3 --><waypoint x="-21483" z="-22037" y="597">	</waypoint>
	<!-- #  4 --><waypoint x="-21605" z="-21973" y="591">	</waypoint>
        <!-- #  5 --><waypoint x="-20393" z="-21331" y="804" tag='Main'>
	if 10 > count1 then   
            queststate = getQuestStatus("Concerned Note");
        if queststate == "complete" then
            -- Complete quest
               player:target_NPC("Shar Talos");
               CompleteQuestByName("Concerned Note");
		local count1 = local count1 + 1
            __WPL:setWaypointIndex(__WPL:findWaypointTag("Main"));   
        else
            -- Accept quest
               player:target_NPC("Shar Talos");
               AcceptQuestByName("Concerned Note");
            __WPL:setWaypointIndex(__WPL:findWaypointTag("Quest"));
        else
	    -- Do Quest
		__WPL:setWaypointIndex(__WPL:findWaypointTag("Quest"));
  	end
else
		inventory:update();
		player:update();
		-- note #202434 is the daily reset card
		if inventory:itemTotalCount(202434) >= 1 then
  		 	 inventory:useItem(202434);
		local count1 = 0
            __WPL:setWaypointIndex(__WPL:findWaypointTag("Main"));
 		else
 			error("No Daily Reset Cards left!")
 			player:sleep();
		end
end
local count1 = local count1 + 1 <- not sure if that works, lol

Re: Local counter

Posted: Wed Oct 24, 2012 3:57 am
by lisa

Code: Select all

count1 = count1 + 1
you already assigned it as local in the onload.

Not sure if there is something about the onload of the WP being changed into a "function" so the local might make it only local to that onload.
So if it doesn't work then just change it to not be local.

Re: Local counter

Posted: Wed Oct 24, 2012 4:19 am
by ZZZZZ
Changed it, but still getting error "Failed to compile and run Lua code for waypoint #6"

It either something wrong with the whole 'count1' or with

Code: Select all

else
      inventory:update();
      player:update();
      -- note #202434 is the daily reset card
      if inventory:itemTotalCount(202434) >= 1 then
             inventory:useItem(202434);
      count1 = 0
            __WPL:setWaypointIndex(__WPL:findWaypointTag("Main"));
       else
          error("No Daily Reset Cards left!")
          player:sleep();
      end
end
as it all worked fine before i started adding extra's >.<

Re: Local counter

Posted: Wed Oct 24, 2012 4:44 am
by lisa
if you are going to make up your own code, which is great, I find this tip useful.

Create a file in userfunctions folder, name it userfunction_whateveryouwant.lua
I use
userfunction_lisafunctions.lua

In that file add any code you want to test in WP as a function.

Code: Select all

function wptester()
   if 10 > count1 then   
            queststate = getQuestStatus("Concerned Note");
        if queststate == "complete" then
            -- Complete quest
               player:target_NPC("Shar Talos");
               CompleteQuestByName("Concerned Note");
      local count1 = local count1 + 1
            __WPL:setWaypointIndex(__WPL:findWaypointTag("Main"));   
        else
            -- Accept quest
               player:target_NPC("Shar Talos");
               AcceptQuestByName("Concerned Note");
            __WPL:setWaypointIndex(__WPL:findWaypointTag("Quest"));
        else
       -- Do Quest
      __WPL:setWaypointIndex(__WPL:findWaypointTag("Quest"));
     end
else
      inventory:update();
      player:update();
      -- note #202434 is the daily reset card
      if inventory:itemTotalCount(202434) >= 1 then
             inventory:useItem(202434);
      local count1 = 0
            __WPL:setWaypointIndex(__WPL:findWaypointTag("Main"));
       else
          error("No Daily Reset Cards left!")
          player:sleep();
      end
end
end
then in the waypoint just call the function.

Code: Select all

<!-- #  5 --><waypoint x="-20393" z="-21331" y="804" tag='Main'>
wptester()
</waypoint>
What this does is give you an actual error message, in the error message it will tell you the line and what is wrong with it.

Once you have the code working the way you want, then just copy it back to that waypoint and you can delete the function.

Doing this will help you solve a lot of the issues you come up against.

Don't make count1 local while testing though as the function will say it is nil.

Re: Local counter

Posted: Wed Oct 24, 2012 6:15 am
by ZZZZZ
Will give it a shot, didn't know about that, thanks :)

Re: Local counter

Posted: Wed Oct 24, 2012 7:12 am
by rock5
First off, if you are going to increment a variable like that then you shouldn't use 'local' at all.

Secondly, you know you don't have to count the times you do the daily? There is a convenient command for that in game. It's mentioned in many posts and is in many daily waypoint files
http://www.theromwiki.com/API:Daily_count

So you could do something like

Code: Select all

if 10 > RoMScript("Daily_count()") then

Re: Local counter

Posted: Fri Feb 08, 2013 11:13 pm
by jalcara
Hi, can u pls up the wp for that quest (concerned note), thx...