Plugin Just stopped working

Posted by Zyn on Sat 18 Aug 2018 10:10 PM — 10 posts, 30,165 views.

#0

<triggers>
  <trigger
   enabled="y"
   keep_evaluating="y"
   match="It is the (\d+)th of (\w+) in the year (\d+)."
   name="Date"
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>SetVariable("T_Date", %1)
SetVariable("T_Month", "%2")
SetVariable("T_Year", %3)</send>
  </trigger>
  <trigger
   enabled="y"
   keep_evaluating="y"
   match="It is the hour of the (\d+)(..) toll."
   name="Time"
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>SetVariable("T_Toll", %1)
</send>
  </trigger>
  <trigger
   enabled="y"
   keep_evaluating="y"
   match="It is the (\w+) of (\w+)\.|It is (\w+) (\w+)"
   name="Season"
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>SetVariable("T_Prefix", "%1")
SetVariable("T_Season", "%2")</send>
  </trigger>
</triggers>

<!--  Timers  -->

<timers>
  <timer name="TTCheck" enabled="y" minute="1" second="0.00" offset_second="0.00"    send_to="12"
group="THTime" active_closed="y" >
  <send>TT()</send>
  </timer>
</timers>
<script>
<![CDATA[
function TT()
	--Variables
		real_time = os.date ("*t")
		if ingame_hour == nil then ingame_hour = tonumber(GetVariable("T_Toll")) end --Toll 
		if ingame_date == nil then ingame_date = tonumber(GetVariable("T_Date")) end -- Date 
		if ingame_month == nil then ingame_month = GetVariable("T_Month") end -- Month (String)
		if ingame_year == nil then ingame_year = tonumber(GetVariable("T_Year")) end -- Year
		if ingame_season == nil then ingame_season = GetVariable("T_Season") end -- Season
		if current_month == nil then current_month = GetVariable("current_month") end
		if Bank_Status == nil then Bank_Status = "Banks are closed" end
		months = {}
		months = {
			'Dawn',
			'Cuspis',
			'Thawing',
			'Renasci',
			'Tempest',
			'Serenus',
			'Solaria', 
			'Torrid',
			'Sojourn',
			'Hoerfest',
			'Twilight',
			'Deepchill'
			}
		real_time_sec = real_time.sec
		real_time_min = real_time.min
		real_time_hour = real_time.hour
		
	-- Suffix changes
	if(ingame_hour == 1 or ingame_hour == 21) then ingame_suffix = "st" 
	elseif ingame_hour == 2 or ingame_hour == 22 then ingame_suffix = "nd"
	elseif ingame_hour == 3 or ingame_hour == 23 then ingame_suffix = "rd"
	else ingame_suffix = "th" end
		
		increase = 1
		
	-- Every 5 minutes is 1 toll. Divide by %5
	if real_time_min % 5 == 0 then
	ingame_hour = ingame_hour + increase
	SetVariable("T_Toll", ingame_hour)
		if(ingame_hour >= 9 and ingame_hour < 11) then
			ColourNote("yellow", "black", "****** It is "..ingame_hour..ingame_suffix.." Toll. Sable Bank is open! *******")
			Bank_Status = "Sable Bank is open!"
		elseif(ingame_hour >= 11 and ingame_hour <= 16) then
			ColourNote("yellow", "green", "****** It is "..ingame_hour..ingame_suffix.." Toll. Both Banks are open! *******")
			Bank_Status = "Both Banks are open!"
		elseif(ingame_hour > 16 and ingame_hour <= 19) then 
			ColourNote("red", "green", "****** It is "..ingame_hour..ingame_suffix.." Toll. Thrace Bank is open! *******")
			Bank_Status = "Thrace Bank is open!"
		else
			Bank_Status = "Banks are Closed"
		end
	else 
		ingame_hour = tonumber(GetVariable("T_Toll")) --Toll
	end
	
	--Find current month and index
	for index, value in pairs(months) do
		if value == ingame_month then
			current_month = index;
		end
	end
	--Checks time for timer
	if(ingame_hour == 25)  -- 0 - 24 tolls
	then 
		ingame_hour = 0 
		SetVariable("T_Toll", ingame_hour)
		ingame_date = ingame_date + increase  
		SetVariable("T_Date", ingame_date)
	elseif(ingame_date > 30)  -- 30 days in a month
		then 
			ingame_date = 1
			current_month = (current_month+1) -- Sets next month
			ingame_month = months[current_month]
	elseif(current_month > 12) -- Next year
		then		
		ingame_year = ingame_year + 1
	end -- 1st if

Amended on Sun 19 Aug 2018 12:02 AM by Zyn
#1

Run-time error
Plugin: Thresholdrpg_time (called from world: ThresholdRPG - Zezyn)
Immediate execution
[string "Plugin: Thresholdrpg_time"]:254: attempt to compare number with nil
stack traceback:
        [string "Plugin: Thresholdrpg_time"]:254: in function 'TT'
        [string "Timer: TTCheck"]:1: in main chunk


I created this small plugin clock and it was working fine until changed colors of the Note. I then started getting errors. I attempted to revert my changes and still get errors. I've checked the variables and they print out the values. I am lost, can you please point me in the right direction?

Let me say I appreciate your time and effort ahead of time, I've been working on this for awhile.

Thank you
(I want to further note I passed this around and other people are using it without a problem. It was working fine and not sure what happened)

Here is the text supposed to be captured by the trigger;

   ---------------------------------------------------
   The current time and date in the realm of Threshold
   ---------------------------------------------------

        It is the 22nd of Solaria in the year 448.    
             It is the hour of the 9th toll.          

               It is the middle of summer.            

   ---------------------------------------------------
Amended on Sat 18 Aug 2018 11:05 PM by Zyn
USA Global Moderator #2
Quote:
[string "Plugin: Thresholdrpg_time"]:254: attempt to compare number with nil

On line 254 of the script section of your plugin (the part after <script>), you tried to see if a number is less than or greater than nil, which is bad.

You've only shown about 70 lines of your plugin's script section, so we can't help yet. Post a link to your full plugin. As you've discovered, the forum doesn't want you to post hundreds of lines of code here.
Amended on Sun 19 Aug 2018 01:24 AM by Fiendish
Australia Forum Administrator #3
As Fiendish said, the line number is relative to the start of the script section, so:


...
<script>
<![CDATA[       <---- this is line 1 of the script
function TT()
...


So, add whatever-that-line-is in your editor to 254, and that will give you the line where the error is (give or take a line).
#4
1st half

<script>
<![CDATA[
function TT()
	
	-----------------------------------------------------------------------------
	
	--REFERENCE FOR THRESHOLDRPG TIMING
	--1 game hour   -  5 REAL minutes
    --1 game day    -  2 REAL hours
    --1 game month  -  60 REAL hours
    --1 game year   -  30 REAL days
     --Dawn  -  January
     --Cuspis  -  February
     --Thawing  -  March
     --Renasci  -  April
     --Tempest  -  May
     --Serenus  -  June
     --Solaria  -  July
     --Torrid  -  August
     --Sojourn  -  September
     --Hoerfest  -  October
     --Twilight  -  November
     --Deepchill  -  December
	
	 --Winter          Spring            Summer         Autumn
     --Deepchill       Thawing         Serenus         Sojourn
     --Dawn            Renasci          Solaria          Hoerfest
     --Cuspis          Tempest         Torrid            Twilight
			 
	-----------------------------------------------------------------------------
	
	--Variables
		real_time = os.date ("*t")
		if ingame_hour == nil then ingame_hour = tonumber(GetVariable("T_Toll")) end --Toll 
		if ingame_date == nil then ingame_date = tonumber(GetVariable("T_Date")) end -- Date 
		if ingame_month == nil then ingame_month = GetVariable("T_Month") end -- Month (String)
		if ingame_year == nil then ingame_year = tonumber(GetVariable("T_Year")) end -- Year
		if ingame_season == nil then ingame_season = GetVariable("T_Season") end -- Season
		if current_month == nil then current_month = GetVariable("current_month") end
		if Bank_Status == nil then Bank_Status = "Banks are closed" end
		months = {}
		months = {
			'Dawn',
			'Cuspis',
			'Thawing',
			'Renasci',
			'Tempest',
			'Serenus',
			'Solaria', 
			'Torrid',
			'Sojourn',
			'Hoerfest',
			'Twilight',
			'Deepchill'
			}
		real_time_sec = real_time.sec
		real_time_min = real_time.min
		real_time_hour = real_time.hour
		
	-- Suffix changes
	if(ingame_hour == 1 or ingame_hour == 21) then ingame_suffix = "st" 
	elseif ingame_hour == 2 or ingame_hour == 22 then ingame_suffix = "nd"
	elseif ingame_hour == 3 or ingame_hour == 23 then ingame_suffix = "rd"
	else ingame_suffix = "th" end
		
		increase = 1
		
	-- Every 5 minutes is 1 toll. Divide by %5
	if real_time_min % 5 == 0 then
	ingame_hour = ingame_hour + increase
	SetVariable("T_Toll", ingame_hour)
		if(ingame_hour >= 9 and ingame_hour < 11) then
			ColourNote("yellow", "black", "****** It is "..ingame_hour..ingame_suffix.." Toll. Sable Bank is open! *******")
			Bank_Status = "Sable Bank is open!"
		elseif(ingame_hour >= 11 and ingame_hour <= 16) then
			ColourNote("yellow", "green", "****** It is "..ingame_hour..ingame_suffix.." Toll. Both Banks are open! *******")
			Bank_Status = "Both Banks are open!"
		elseif(ingame_hour > 16 and ingame_hour <= 19) then 
			ColourNote("red", "green", "****** It is "..ingame_hour..ingame_suffix.." Toll. Thrace Bank is open! *******")
			Bank_Status = "Thrace Bank is open!"
		else
			Bank_Status = "Banks are Closed"
		end
	else 
		ingame_hour = tonumber(GetVariable("T_Toll")) --Toll
	end
	
	--Find current month and index
	for index, value in pairs(months) do
		if value == ingame_month then
			current_month = index;
		end
	end
	--Checks time for timer
	if(ingame_hour == 25)  -- 0 - 24 tolls
	then 
		ingame_hour = 0 
		SetVariable("T_Toll", ingame_hour)
		ingame_date = ingame_date + increase  
		SetVariable("T_Date", ingame_date)
	elseif(ingame_date > 30)  -- 30 days in a month
		then 
			ingame_date = 1
			current_month = (current_month+1) -- Sets next month
			ingame_month = months[current_month]
	elseif(current_month > 12) -- Next year
		then		
		ingame_year = ingame_year + 1
	end -- 1st if
	
	
	
	Display_Threshold_Time(ingame_season, ingame_year, ingame_month, ingame_suffix, ingame_date, ingame_hour, Bank_Status) -- Send to Window
	
end -- TT
function Display_Threshold_Time(Season, Year, Month, Suffix, Date, Hour, Bank)
	THTime = "THTime_" .. GetPluginID () .. ":ThresholdTime" -- get a unique name, ensure not empty if outside plugin
	
	local font = "f"
	local font2 = "f2"
	
	WindowCreate (THTime, 0, 0, 0, 0, 6, 0, 0) -- Create Window Placeholder
	--creating Fonts
	-- Trebuchet MS, 28 point, bold
	WindowFont (THTime, font, "Trebuchet MS", 12, true, false, false, false)
	WindowFont (THTime, font2, "Trebuchet MS", 10, true, false, false, false)
	local max_width = WindowTextWidth(THTime, font, "The Time in Threshold")
	local font_height = WindowFontInfo(THTime, font, 1)
	local window_width = max_width + 40
	local window_height = font_height * 4
	
	--make window with size
	WindowCreate(THTime, 0, 0, window_width, window_height, 6, 0, ColourNameToRGB("black"))
	WindowRectOp(THTime, 5, 0, 0, 0, 0, 5, 15 + 0x1000) -- Border 
	
	-- Heading
	WindowText(THTime, font, "The Time in Threshold", 25, 5, 0, 0, ColourNameToRGB("white"), false)
	
	--Each line
	local y = font_height + 2 --Font Y axis
	local x = 5 -- Font X axis
	
	--Time and Date
	WindowText(THTime, font, Hour..Suffix.." Toll  ", (x+2), (y+20), 0, 0, ColourNameToRGB("magenta"), false) -- Toll
	WindowText(THTime, font, Month.." "..Date..", "..Year..";  "..Season, x, y, 0, 0, ColourNameToRGB("magenta"), false) -- Adds Month/date/year
	
	if Bank_Status == "Thrace Bank is open!" or Bank_Status == "Sable Bank is open!" or Bank_Status == "Both Banks are open!" then 
	WindowText(THTime, font2, Bank, (x+75), (y+23), 0, 0, ColourNameToRGB("green"), false) -- Bank Hours open
	else WindowText(THTime, font2, Bank, (x+75), (y+23), 0, 0, ColourNameToRGB("red"), false) end -- Bank Hours closed 
	
	--Real Time & Date
	WindowText(THTime, font, (os.date("%I")..":"..os.date("%M").." "..os.date("%p").." "..os.date("%x")) , x+35, y+40, 0, 0, ColourNameToRGB("white"), false)
	
	WindowShow(THTime, true) -- Show window
	
end -- Display_Threshold_Time
]]>
</script>
USA Global Moderator #5
What do you mean "first half"?
#6
I apologize I should have explained better. The first post was the beginning of the plugin with the triggers, the second post was just the script as requested. I have tried reinstalling MUSHclient 5.05 hoping that would help. It did not. From what I understand the ingame_date variable is now nil which leaves me to believe the trigger isn't capturing the line and setting the variable. I have made a new test trigger to see if I can capture the line and it works. I compare the new test trigger with the old trigger and the regular expression is the same. I am not sure what I am doing differently in the plugin to where this is not working. If I comment out anything to do with the ingame_date variable the plugin runs and works.
#7
Ok an update. I have been testing and trying for a good few hours. I remade the script into another plugin with a different name, where previously I was overwriting the original plugin I created. Now that I have created a new plugin with a different name it works. I'm still unclear where I broke the last one. I thank you for your time and help. I greatly enjoy using MUSHclient and think it's one of the better clients out. Please keep up the good work and I appreciate the responses. :)
Australia Forum Administrator #8
Quote:


        It is the 22nd of Solaria in the year 448.    



Trigger:

Quote:


   match="It is the (\d+)th of (\w+) in the year (\d+)."



That won't match (it isn't the 22th of Solaria) thus your date won't be set. If the first time you test it, you happen to get a "th" date then the date will be set and stay set until another "th" date comes along.

Maybe make the trigger:


   match="It is the (\d+).. of (\w+) in the year (\d+)."



Or:



   match="It is the (\d+)(?:st|nd|rd|th) of (\w+) in the year (\d+)."
Amended on Sun 19 Aug 2018 08:45 PM by Nick Gammon
#9
I didn't think of that!! LOL. Always miss the easy things. I was able to duplicate the original problem I had though. After creating the plugin with the plugin wizard provided in MUSHclient, I attempted to alter the timer in the plugin file. I save the file, reload the plugin and that's when I started getting the same error as before. I hope this helps. Also Thanks Nick you're absolutely right and am fixing that issue now.

Thank you for all your time!