Problem loading variables

Posted by LezChap on Mon 29 Mar 2010 03:32 AM — 4 posts, 16,861 views.

#0
I have a plugin script similar to the following (just a snippit of the problem areas):


  <trigger
   enabled="y"
   keep_evaluating="y"
   match="^Welcome back, (.+)\.$"
   name="TriggerWelcomeBack"
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>
  SetTableName("%&lt;1&gt;")</send>
  </trigger>

function SetTableName(TableName)
  TableName = string.gsub (TableName, "[^%a%d]", "_") --replace all non-letters or numbers with _ 
  if TableName ~= dbTable then
    dbTable = TableName
    SetVariable ("DBTable", dbTable)
  end
  ColourNote("Cyan","black", "Using "..dbTable.."'s data as the Current Data for People_Met Plugin.")
end --function

function Start()
  dbTable = "Table"
  local dbTableCheck = GetVariable("DBTable")
  if dbTableCheck ~= nil and dbTableCheck ~= "" then	
    SetTableName(dbTableCheck)
  end
end --function

function OnPluginInstall ()
  Start()
end -- OnPluginInstall


function OnPluginEnable ()
  Start()
end -- OnPluginEnable


Problem is when Start() finds a valid value in DBTable, and sends it to SetTablename(), the script seems to stop working as it should...Notes and Tells that the script should send to the mud window stop working. Variables are still set and updated, however.

It seems like the problem is on the "SetVariable" line (debugging and commenting out code), but I can't figure out how to fix it. Any ideas?
Amended on Mon 29 Mar 2010 03:33 AM by LezChap
Australia Forum Administrator #1
Right, so in a somewhat roundabout way, your script is setting the variable "DBTable" to whatever name appeared in the trigger?

So what goes wrong, exactly?
#2
It does that part just fine...if the trigger goes off after the script it freshly installed (with no save state), it runs through the whole thing fine, and does the ColourNote, as well as the rest of the script. If the trigger goes off again, it's still fine.

Now when I close the world, and re-open it, it should read the Variable, send it to SetTableName() and display the ColourNote...It does the first part just fine (loads the variable and sends it to SetTableName()), but the script stops displaying the ColourNote (and all other Notes, ColourNotes, Tells, and ColourTells in the script). If the trigger matches, it'll parse the name in the trigger to SetTableName(), but still fail to display and Notes/Tells.

Another thing I noticed is when it's failing to display Notes and Tells, the text entered in "Test Trigger..." changes from the default gray it used to display as, to the blue color that is the same as the default for Notes. (Currently only doing offline testing)
Amended on Mon 29 Mar 2010 04:03 AM by LezChap
Australia Forum Administrator #3
Ah, OK I see.

At world startup the plugins are loaded before the main window is initialized. Thus any world notes very early on are simply discarded.

The work around is to delay that processing slightly, for example something like this:


function OnPluginInstall ()
  DoAfterSpecial (1, "Start()", sendto.script)
end -- OnPluginInstall


And I wouldn't really bother doing it on the plugin enable, what will that achieve?