Showing posts with label c#. Show all posts
Showing posts with label c#. Show all posts

Monday, March 20, 2017

C# trick to launch runtime debugger

I have used this trick quite successfully many times to launch a debugger from a running application. It works really well for things that are hard to debug.  Things like DLLs that might be running under a different application, or display tasks that happen periodically and launching the application in the debugger might change the way the application runs and not cause the bug you are looking for.  It works by basically crashing the application with an exception which brings up the dialog to allow you to continue or debug.  You can have visual studio already loaded with the application and choose that instance of VS from the list.  It is a one liner that you add to your code.

So simple. In your C# code, simply add this line.

Debugger.Launch();

You can do this in any language, but I'm using c# at the moment so showing that. This is very handy.

Tuesday, July 12, 2016

WinForms C# ctrl-z for undo and redo

I have a personal application I built to help sort pictures. It works really well for me, but no where near commercial quality. Every so often I add a new little feature to it.  This time I'm adding undo and redo.  The control key for handling was a little different than I expected and I had to look it up so I thought I would add it for my own future reference.

        bool bUndoDown = false;

        // checking for ctrl key
        private void Form1_KeyDown(object sender, KeyEventArgs e)
        {

            switch (e.KeyCode)
            {

                case Keys.Z:
                    if (bUndoDown)
                        break;

                    if (e.Modifiers == (Keys.Control | Keys.Shift))
                    {
                        bUndoDown = true;
                        Console.WriteLine("redo pressed");
                    }
                    else if (Control.ModifierKeys == Keys.Control)
                    {
                        bUndoDown = true;
                        undodebugcnt++;
                        Console.WriteLine("undo pressed "+undodebugcnt);
                    }
                    break;
            }
        }


    private void Form1_KeyUp(object sender, KeyEventArgs e)
        {
            if (bUndoDown)
            {
                if (e.KeyCode==Keys.Z)
                {
                    bUndoDown = false;
                }
            }
        }

I originally thought I could get this to work with just the KeyPressed event, but had to do it a little deeper in the KeyDown and KeyUp events.

Friday, June 5, 2015

Datacap C# Smart Parameter parsing using MetaWord

I keep having to look up how to get a smart parameter in Datacap using both C# and VBScript. Figure it's time to leave myself a breadcrumb.

Here is the sample in C#, it comes directly from the vScanSample where I always look for it.
        public bool myact_set_folder(string sPath)      // set the folder to search for files
        {
            dcSmart.SmartNav localSmartObj = null;
            try
            {
                localSmartObj = new dcSmart.SmartNav(this);
                //If the parameter is a smart parameter, look up the actual path (returns the original path if it was not a smart parameter)
                mFolderPath = localSmartObj.MetaWord(sPath);
                RRLog.Write("Image source folder set to: " + mFolderPath);
            }
            catch (Exception ex)
            {
                RRLog.Write("myact_set_folder error: " + ex.ToString()); 
                return false;
            }
            finally
            {
                localSmartObj = null;
            }

            return true;
        }


Here is the VBScript Datacap custom action version to parse the smart parameter. This comes directly from one of my own custom actions I use for doing text searching.

   'Get the smart parameter for the FinderString
    sTmp = MetaWord(FinderString)
    If (sTmp = "") Then 'Field Value
        Set oChild = CurrentObj.FindChild(Right((FinderString), Len((FinderString))-1))
        If Not(oChild Is Nothing) Then
           WriteLog("Hostname from field")
           sTmp = oChild.Text
    Set oChild = Nothing
        End If
    End If
    ValueToSearch = sTmp
    WriteLog("ValueToSearch = " & ValueToSearch)

Hope I remember that I left myself this note here

Wednesday, April 15, 2015

c# getters and setters

I keep having to lookup the c# syntax for getters and setters.  Nothing to fancy, just figure I'll leave myself a bread crumb.


    private int iCurCell;
    public int CurCell
    {
        get { return iCurCell; }
        set { this.iCurCell = value; }
    }

Thursday, January 29, 2015

Unity2D script to programatcally add a sprite

I'm create a grid of tiles. The tiles are sprites and I'm laying them out programmatically. Here is the code to generate one of the tiles.

public Sprite tile_plain; // assign this in unity by dragging a sprite to it void Start() { GameObject tile = new GameObject(); tile.AddComponent(); tile.GetComponent().sprite = tile_plain; tile.transform.position = new Vector2((i * tile_plain.rect.width)/tile_plain.pixelsPerUnit, 5f); }

Wednesday, January 14, 2015

Unity script referencing



I wanted my keyboard input script to retrieve a value from a grid generator script so it knew how far to move one of my game objects. It took me a while to figure it out even though it's simple so I figure it's best to leave myself a bread crumb so I don't have to search so much next time.

//this is how you get a reference and value out of another script
scriptholder = GameObject.Find("EmptyScriptHolder");
GridManager script = scriptholder.GetComponent<GridManager>();
print("Grid gap =" + script.stepsize);


This shows how to get a reference to the actual script, in this case it's my EmptyObject I use to hold scripts that are not associated with actual GameObjects.  I call it EmptyScriptHolder.  I then get the reference to the GridManager script.  This is the actual type name of the script.  Within that script is a method variable called stepsize.  Overall it's very simple to get a value out of another script once you know how to do it.

This site was very helpful even though it's documentation from a few versions back.
http://docs.unity3d.com/412/Documentation/ScriptReference/index.Accessing_Other_Game_Objects.html

Monday, August 17, 2009

Class preparation

I've been putting all my extra time into a class I will be teaching at Chapman University next semester. We'll be using XNA and C# to build an open source game engine. I have the project all setup, the training and managment of subversion is ready and I have a pretty good outline and a good direction for the engine. I've done a few games using XNA, but for the tool side needed to figure out the WinForms integration and found these microsoft sites on WinForms/XNA to be very helpful.

I'm a blender fan, but I really need to train people on 3dsMax. I purchased an edu copy a year ago (still way to expensive) and I'm finally forcing myself to use it. I've been going through the tutorials and think it will be a good way to learn max. I also need to get through all the skeleton animation stuff so I know how to do it in Max. I've done it with Blender, but for this class I really need to use the tools that we have on the computers in class.

It starts in two weeks. I have a ton of material so far, but there is still a lot to go over.

I also went back and looked at the pinball game in second life and I have been itching to do some more work on it. I finally think I know how to fix the bumper mechanic and add a little skill to the game. Too much going on at this point, but hopefully the idea can slowly rise to the top of the queue and I can do some more work in SL since I enjoy that environment.

Wednesday, March 25, 2009

Skeet Slider game

I didn't even think I was going to be able to get a game done this week. I was spending a bunch of time on HLSL (the XNA shader language) and not getting where I needed to get. I decided I still needed to get a game done this week and I have yet to do a 2D game using XNA so I decided (yesterday) that would be the best way to complete the project in the time left.

The game is called Skeet Slider. Not my best by far, but much better than the past few weeks while I've been learning the XNA framework. You slide a puck across the bottom of the screen trying to avoid bouncing blocks. It's all about timing. I wanted to add a feature to change the velocity of the puck, but I'm out of time. Here is a screen shot of the game on level 4, the highest level. I spent a little time at the end to add better art for the game so it is cleaner that what I've written in XNA so far.



I also messed with the publish system in XNA Game Studio 3.0 and created an installer you can use to run the game. It is available here: http://www.woodsgoods.com/gawxna/01skeetslider.

I have also been considering offering the source code to some of these games to try and cover some of my time. It's a minimal $5 to purchase the C# source code to the Skeet Slider XNA Game. Please tell me if you think this is reasonable or not? I could really use some feedback.