reader.readstring()

May 3, 2012 at 7:01 AM

Squizzle I'm seeing Exception errors with reader.readstring()

It works fine for the first 3 executions.. then reader.readstring reads Null and throws reader Exception.

I'm using the Latest Subversion.

 

New

            SilverMonkey.Main.MSpage.SetTriggerHandler(Monkeyspeak.TriggerCategory.Cause, 23,
                 AddressOf msgContains, "(0:23) When someone emits something with {...} in it,")
        Function msgContains(reader As TriggerReaderAs Boolean
            Debug.Print("msgContains Begin Execution")
            Dim msMsg As String = reader.ReadString()
            Debug.Print("msMsg = " & msMsg)
 
            Dim msg As String = Main.MSpage.GetVariable("%~Message").Value
            Return msg.Contains(msMsg)
 
 
        End Function


'Channel Parser
        ElseIf Channel = "dragonspeak" OrElse Channel = "emit" Then
            Try
                sndDisplay(fIcon(data) & Text, fColorEnum.Emit)
 
                Debug.Print("Executing Emit Triggers:")
                Debug.Print("Channel = " & Channel)
                Debug.Print("Text = " & Text)
                PageSetVariable("EmitMessage", Text)
                ' Execute (0:21) when someone emits something
                PageExecute(21)
                ' Execute (0:22) when someone emits {...}
                PageExecute(22)
                ' Execute (0:23) when someone emits something with {...} in it
                PageExecute(23)

Wrappers

    Public Sub PageSetVariable(ByVal varName As StringByVal data As Object)
        If cBot.MS_Engine_Enable AndAlso MS_Started() Then
            MSpage.SetVariable("%~" & varName, data, True) '
        End If
    End Sub
 
    Public Sub PageExecute(ByVal TriggerCause As Integer)
        If cBot.MS_Engine_Enable AndAlso MS_Started() Then
            MSpage.Execute(Monkeyspeak.TriggerCategory.Cause, TriggerCause)
        End If
    End Sub


PS:
page.setvariable Constants are false with PageSetVariable Wrapper

May 3, 2012 at 7:03 AM

Not sure if this is related but I Continued after getting repeats of the reader exceptions and I got this

 

System.Transactions Critical: 0 : <TraceRecord xmlns="http://schemas.microsoft.com/2004/10/E2ETraceEvent/TraceRecord" Severity="Critical"><TraceIdentifier>http://msdn.microsoft.com/TraceCodes/System/ActivityTracing/2004/07/Reliability/Exception/Unhandled</TraceIdentifier><Description>Unhandled exception</Description><AppDomain>SilverMonkey.vshost.exe</AppDomain><Exception><ExceptionType>System.InvalidOperationException, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</ExceptionType><Message>The Undo operation encountered a context that is different from what was applied in the corresponding Set operation. The possible cause is that a context was Set on the thread and not reverted(undone).</Message><StackTrace>   at System.Threading.SynchronizationContextSwitcher.Undo()
   at System.Threading.ExecutionContextSwitcher.Undo()
   at System.Threading.ExecutionContext.runFinallyCode(Object userData, Boolean exceptionThrown)
   at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteBackoutCodeHelper(Object backoutCode, Object userData, Boolean exceptionThrown)
   at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Net.ContextAwareResult.Complete(IntPtr userToken)
   at System.Net.LazyAsyncResult.ProtectedInvokeCallback(Object result, IntPtr userToken)
   at System.Net.Sockets.BaseOverlappedAsyncResult.CompletionPortCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* nativeOverlapped)
   at System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP)</StackTrace><ExceptionString>System.InvalidOperationException: The Undo operation encountered a context that is different from what was applied in the corresponding Set operation. The possible cause is that a context was Set on the thread and not reverted(undone).
   at System.Threading.SynchronizationContextSwitcher.Undo()
   at System.Threading.ExecutionContextSwitcher.Undo()
   at System.Threading.ExecutionContext.runFinallyCode(Object userData, Boolean exceptionThrown)
   at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteBackoutCodeHelper(Object backoutCode, Object userData, Boolean exceptionThrown)
   at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Net.ContextAwareResult.Complete(IntPtr userToken)
   at System.Net.LazyAsyncResult.ProtectedInvokeCallback(Object result, IntPtr userToken)
   at System.Net.Sockets.BaseOverlappedAsyncResult.CompletionPortCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* nativeOverlapped)
   at System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP)</ExceptionString></Exception></TraceRecord>

May 3, 2012 at 9:17 PM

Update:

revision 88760 Works perfectly. So theres Something with the TriggerReader in the current Revision thats amiss

Coordinator
May 4, 2012 at 4:34 AM
Edited May 4, 2012 at 4:35 AM
Debug.Print("msMsg = " & msMsg)

What does that print?

TriggerReader is suppose to raise an exception if it cannot find a value.  It'll raise a TriggerReaderException with the message "No value found."   If you want to avoid the exception use TriggerReader.PeekString which will return true if the next value is a string.

 

The stacktrace in the exception you posted has nothing linking to Monkeyspeak namespace so I can tell you its not related to Monkeyspeak.

May 4, 2012 at 8:28 PM
Edited May 4, 2012 at 8:53 PM
Squizzle wrote:
Debug.Print("msMsg = " & msMsg)

What does that print?


msMsg = {Nothing}

Since I have the Monkeyspeak Loaded into my Solution

Dim msMsg As String = reader.ReadString() 
Takes me to ReadString where it throws the errors.

Now that I reverted to 88760. I'm getting a Similar Problem with ReadVariable

It's like the Data is falling into a Black hole getting lost some where

Silver Monkey Project with Test Dream
http://www.ts-projects.tk/download/Silver%20Monkey.rar
Coordinator
May 5, 2012 at 2:36 AM
Edited May 5, 2012 at 3:43 AM

Use the latest source for debugging please.  There are a lot of changes to TriggerReader in the newest source and any bugs need to be addressed with that new version.  I can't help you with previous versions.

If there is an exception with ReadString could you post it here the information is valuable in determining the source of the error.

Also I updated the docs and the new additions to the TriggerHandler "TriggerReader" part of the page might help you out.

May 5, 2012 at 7:05 AM
Edited May 5, 2012 at 7:14 AM

Ok Updated to latest Subversion

Changed this only rest of the Code is the Same

        Function msgContains(reader As TriggerReaderAs Boolean
            Debug.Print("msgContains Begin Execution")
            Dim msMsg As String = reader.ReadString()
            Debug.Print("msMsg = " & msMsg)
            Dim msg As String = Main.MSpage.GetVariable("%~Message").Value.ToString
            Debug.Print("Msg = " & msg)
            Return msg.Contains(msMsg)
        End Function

msgContains Begin Execution
msMsg = PlaceBet1
Msg =   Welcome to the <a href=http://www.furcadia.com/maps/silvershowcase.jpg>Silver Sponsor's Showcase</a>! Everyfurre is welcome here in this lush jungle dream. Sponsors may upload to the portals by choosing their gem color with F3 on the portals  and then facing for the control-t upload. Be sure to take a ride on a friendly turtle while you are here. For more info on becoming a sponsor, go to http://www.furcadia.com/digomarket (Dream by Gemedet, Ryhn, Zephyr and others.)
msgContains Begin Execution

Then Exception "invalid Operation. Queue empty"

		public string ReadString(bool processVariables = true)
		{
			try
			{
				string str = Convert.ToString(cloneTrigger.contents.Dequeue()); <<< 

Continued and got TriggerReaderException. No value found

			catch
			{
				throw new TriggerReaderException("No value found."); <<<
			}

Continued again Exception occured in SayLibrary, msgContains with (0:23)

in
public void Execute(TriggerCategory cat, int id) brings me to break;
 
Continued again
I get the Stack Trace and Boomb Program Closes
		public void Execute(TriggerCategory cat, int id)
Coordinator
May 5, 2012 at 11:08 PM

Thank you that says a lot and I believe I fixed it.  What was happening was the internal Queue that held the values in the TriggerReader was reaching the end of the Queue.  So it should throw a exception if that happens.  Again I RECOMMEND you use Peek* methods in the TriggerReader class because those help avoid those costly exceptions.

 

The new changes to TriggerReader make it so that you *have to* read Trigger values *in the order that they are added*.  Please read the new documentation on TriggerHandlers.

May 6, 2012 at 12:26 AM
Edited May 6, 2012 at 1:40 AM

I've Always Assumed Order of Trigger Values was required.. Though VB.Net Example has a Bug in 2000+ to Console due to the order being used

Problem isn't about Avoiding the Exception Errors.. Its about the Data getting Lost,. If theres Data Exceptions are Avoided...  I Don't want to slap on a Bandaid when stitches are needed. I think I prefer the Exception errors because the Data is getting lost. Peek methods might Make it harder to Spot the Trouble

I think it'd be better to put the reads into a try,catch Statement

            Try
reader.readstring
reader.readnumber
Catch
 ex As Exception                 Console.WriteLine(ex.Message)                 Return False             End Try

This would Give the User a way to Syntax Check thier Scripts
Would be great if there was a Way to Print the Line Number of the Script file Thworing the Error

IE:
Line: 1 MSpeak: (0:1) Invalid Syntax

Test MonkeySpeak

(0:0) When the bot starts,
        (5:400) use SQLite database file {%~msPath/Arena.S3db} or create file if it does not exist with table "Furre".
        (5:401) Create table {Fighter1} if it does not exist.
        (5:402) Create column {Name} in table {Fighter1} if it does not exist.
        (5:402) Create column {[Bid Ammount]} in table {Fighter1} if it does not exist.
        (5:401) Create table {Fighter2} if it does not exist.
        (5:402) Create column {Name} in table {Fighter2} if it does not exist.
        (5:402) Create column {[Bid Ammount]} in table {Fighter2} if it does not exist.


*PlaceBet1 "~bettingname" - %betamount
 (0:23) When someone emits something with {PlaceBet1} in it,
 (5:110) use variable %~Message and take word 2 and put it into variable %name
        (5:110) use variable %~Message and take word 3 and put it into variable %ammount

 

I Updated My Subversion to your recent

msMsg = PlaceBet1
Msg =   Welcome to the <a href=http://www.furcadia.com/maps/silvershowcase.jpg>Silver Sponsor's Showcase</a>! Everyfurre is welcome here in this lush jungle dream. Sponsors may upload to the portals by choosing their gem color with F3 on the portals  and then facing for the control-t upload. Be sure to take a ride on a friendly turtle while you are here. For more info on becoming a sponsor, go to http://www.furcadia.com/digomarket (Dream by Gemedet, Ryhn, Zephyr and others.)
msgContains Begin Execution

ReadString

TriggerReaderException: End of values reached.

PeekString test

        Function msgContains(reader As TriggerReaderAs Boolean
            Debug.Print("msgContains Begin Execution")
            Dim msMsg As String = ""
            If Not reader.PeekString Then msMsg = reader.ReadString()
            Debug.Print("msMsg = " & msMsg)
            Dim msg As String = Main.MSpage.GetVariable("%~Message").Value.ToString
            Debug.Print("Msg = " & msg)
            Return msg.Contains(msMsg)
        End Function

msgContains Begin Execution
msMsg =
Msg =   Welcome to the <a href=http://www.furcadia.com/maps/silvershowcase.jpg>Silver Sponsor's Showcase</a>! Everyfurre is welcome here in this lush jungle dream. Sponsors may upload to the portals by choosing their gem color with F3 on the portals  and then facing for the control-t upload. Be sure to take a ride on a friendly turtle while you are here. For more info on becoming a sponsor, go to http://www.furcadia.com/digomarket (Dream by Gemedet, Ryhn, Zephyr and others.)

Ok So I'm Still Loosing msMsg when it Should be "PlaceBet1"
Where's the Black Hole of Null Stealing my Values?

Now ReadNumber is Loosing Data in a diferent MS Line Since I Used the PeekString Bandaid.
The Queueing System Needs some Open Heart Surgery


 
Coordinator
May 6, 2012 at 5:34 AM
Edited May 6, 2012 at 5:48 AM

I see what you are saying sorry had a stupid moment there.  I thought the problem lied in the way you were using TriggerReader, I was wrong. =,/  I have an idea of what the problem is.  Thank you and I will fix it.

Btw

If Not reader.PeekString Then should be If reader.PeekString Then...

Yep my changes also fix the Timer library which will work correctly instead of only getting processed once.  Major bug that was...  it'll be in the next build in a moment.

Coordinator
May 6, 2012 at 5:53 AM
Edited May 6, 2012 at 6:08 AM

Fixed.  See the newest release r4

Coordinator
May 6, 2012 at 6:29 AM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.