none
Need help with this coding of mine. RRS feed

  • Question

  • I'm working on an assignment, and I have to make a game in Small Basic, here I thought that I'd use the same script that I had for a selection screen, but just modify it a bit so I can make a better looking screen. Well, I got this error:
       bij System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
       bij System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
       bij System.Delegate.DynamicInvokeImpl(Object[] args)
       bij System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Boolean isSingleParameter)
       bij System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)
       bij System.Windows.Threading.DispatcherOperation.InvokeImpl()
       bij System.Threading.ExecutionContext.runTryCode(Object userData)
       bij System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
       bij System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       bij System.Windows.Threading.DispatcherOperation.Invoke()
       bij System.Windows.Threading.Dispatcher.ProcessQueue()
       bij System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
       bij MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
       bij MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
       bij System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Boolean isSingleParameter)
       bij System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)
       bij System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Boolean isSingleParameter)
       bij MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
       bij MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
       bij System.Windows.Threading.Dispatcher.TranslateAndDispatchMessage(MSG& msg)
       bij System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
       bij System.Windows.Application.RunInternal(Window window)
       bij Microsoft.SmallBasic.Library.Internal.SmallBasicApplication.<>c__DisplayClass1.<.cctor>b__0()
       bij System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       bij System.Threading.ThreadHelper.ThreadStart()

    And here is my coding:

    GraphicsWindow.KeyDown = OnKeyDown
    Setup()
    Start()

    Sub OnKeyDown
      key = GraphicsWindow.LastKey
      If varG = "Start" Then
        If key = "Up" Or key = "Down" Then
          If varStart1 = "Active" Then
            If key = "Up" Then
              varStart1 = "Unactive"
              varStart2 = "Unactive"
              varStart3 = "Active"
            ElseIf key = "Down" Then
              varStart1 = "Unactive"
              varStart2 = "Active"
              varStart3 = "Unactive"
            EndIf
          ElseIf varStart2 = "Active" Then
            If key = "Up" Then
              varStart1 = "Active"
              varStart2 = "Unactive"
            ElseIf key = "Down" Then
              varStart2 = "Unactive"
              varStart3 = "Active"
            EndIf
          ElseIf varStart3 = "Active" Then
            If key = "Up" Then
              varStart3 = "Unactive"
              varStart2 = "Active"
            ElseIf key = "Down" Then
              varStart3 = "Unactive"
              varStart1 = "Active"
            EndIf
          EndIf
        EndIf
        Start()
      EndIf

    varG gets it's value in Start(), and it will get the value "Start". The Setup is just to define varStart1 to 3 and the paths. Here is my Start() just in case it's needed:

    Sub Start
      varG = "Start"
      Sound.Play(SoundPath + "\Start.mp3")
      GraphicsWindow.DrawImage(ImagePath + "\Start.jpg",0,0)
      If varStart1 = "Active" Then
        GraphicsWindow.BrushColor = "yellow"
        GraphicsWindow.DrawText(390,200, "New Game")
        GraphicsWindow.BrushColor = "Moccasin"
      ElseIf varStart1 = "Unactive" Then
        GraphicsWindow.DrawText(390,200, "New Game")
      EndIf
      If varStart2 = "Active" Then
        GraphicsWindow.BrushColor = "yellow"
        GraphicsWindow.DrawText(390,220, "Load Game")
        GraphicsWindow.BrushColor = "Moccasin"
      ElseIf varStart2 = "Unactive" Then
        GraphicsWindow.DrawText(390,220, "Load Game")
      EndIf
    EndSub

    I hope to see a reply soon, and thank you very much for your time~.

    Saturday, January 4, 2014 4:57 PM

Answers

  • So is the error reproducible (consistently happens)?

    Please post code (or upload using Publish feature on SB interface and post 6 character publish ID) that can cause the error (so we don't have to edit it and maybe change what you are seeing) and provide any instructions like which keys to press to cause it.

    Basically, unless it can be reproduced it is very hard to help without loads of guessing.

    Saturday, January 4, 2014 7:06 PM
    Moderator

All replies

  • Hi,

    The subroutine Setup is not defined and there is no EndSub for OnKeyDown; also  SoundPath and ImagePath are undefined - so clearly we cannot be running the same code.

    Now guessing what Setup might do:

    GraphicsWindow.KeyDown = OnKeyDown
    'Setup()
    varStart1 = "Active"
    Start()

    With this I get no error.

    I can't see what could cause the error.  Suggest you simplify the code so that it can be run without image and sound files (unless these are the problem) and some-one looking at the code can run it and reproduce the error.

    Saturday, January 4, 2014 5:44 PM
    Moderator
  • Ah thanks for the help, but I already tried simplifying it. In Setup, everything gets defined, so the soundpath and imagepath aswell, and all the variables I use, giving them a base value.  I forgot to copy the EndSub part on OnKeyDown so it didn't show on this post, sorry!
    Saturday, January 4, 2014 6:29 PM
  • So is the error reproducible (consistently happens)?

    Please post code (or upload using Publish feature on SB interface and post 6 character publish ID) that can cause the error (so we don't have to edit it and maybe change what you are seeing) and provide any instructions like which keys to press to cause it.

    Basically, unless it can be reproduced it is very hard to help without loads of guessing.

    Saturday, January 4, 2014 7:06 PM
    Moderator
  • Hi there XerexesMeow

    I've read with these huge error reports that the first couple of lines will hold the clue to what's up with the code.

    So in your error report it states: "InvokeMethodFast(Object target, Object[]" and then " Boolean skipVisibilityChecks)" and then "ExceptionWrapper.InternalRealCall(Delegate callback, Object args". I don't think it's important to know what all this stuff means but there's a clue here, somethings looking for something to do something and it doesn't seem to be there.

    Also you mention you designed your program on a screen selection program. 

    You can get an error when you try to do something that requires the GraphicsWindow to be VISIBLE.

    I'd be checking any SB methods that run when the GW is NOT VISIBLE. Maybe sound, shapes.

    Also note that I've been able run code on my PC but when others run it on theirs they get an error. One case was a Hide Show thing I was doing with the GW.


    Friday, January 10, 2014 9:03 PM
    Moderator
  • Hi XerexesMeow

    Have you resolved this issue? If not post a sample and we'll see if someone can help.

    Monday, January 20, 2014 7:14 AM
    Moderator