Better living through Scratch (Meta #8)

I’m not sure if this fits into my already ill-defined “meta” category but I’m going to go with it.

Since my last meta, I actually started a new game which assuming I ever finish (looks like at least 100 hours for completion, probably more) I will post a review for. I also watched a couple more TV shows. It’s funny I went back and re-read Meta #7 and it was like reading something from 10 years ago. I guess a few things have happened since Presidents Day 2020.

But this entry isn’t supposed to be about those things, this is about my possible renewed interest is programming.

A few weeks ago for no particular reason I started doing some experimenting in Scratch, a non-typed programming environment largely aimed kids (age 10 or whatever). But as it turns out Scratch v3 (the latest as I type this) has some relatively advanced features and things can kind of be “slapped together” really quickly.

For instance, a left/right space ship shooter game with scrolling star field can be put together quite quickly with a only a few blocks.

That’s how Scratch works: literally drag and drop different blocks for if/else, while and a few other loops and then drop actions inside of those loops. Then perhaps wrap it all in a “forever” loop.

There’s sprites that can imported or created from a blank editor and then the blocked off “code” can be associated with that specific sprite.

In scratch you can actually utilize custom variables, functions, arrays and a few other things. If you want a sprite to point towards another sprite there’s literally a “point towards ____” block. If you want that sprite to then gradually move towards the second sprite there’s a “glide to in ___ seconds” block. They all stack together like jigsaw pieces.

I ended up watching a few different YouTube playlists on creating different kinds of games (turns out Scratch v2 doesn’t work so good with Scratch v3). There’s also a gallery of pretty sophisticated games to go through all of which have their “code” exposed for anyone look at and “fork” (they have a different term for “fork” – remix – but it’s the same idea).

All this helped me with a few more advanced topics I was having some issues with conceptually. For instances the this. convention always confused me but Scratch makes this obvious. The same with the concept of a “game loop” that I mostly understood but probably not entirely.

Once you get past the in-your-face “this is for kids!!” nature of the website the language is actually pretty robust. And the examples of the associated Wiki are also relatively advanced.

I wrote all that so I could get to this: in 2019 I was trying pretty full-on really really learn PowerShell to the point of marking off boxes on my wall calendar and keeping track of things. I was also reading, re-reading, highlighting, deconstructing and writing out my PowerShell book. Then before I was done with I started on the “100 days of code” thing as a concept.

I think all these combined into some kind of mental overload such that one day I stopped and very rarely if ever went back to even using PowerShell never mind re-opening that book. I think it’s been probably 10 months since I even opened that book. Even though I think I was on chapter 19 of 25 chapters. Just super close.

I guess it had been long enough combined with the relative ease of getting a working thing with Scratch that I started re-looking at some different projects.

For instance there’s a relatively insignificant utility I wrote for use at my work I’ve been meaning to re-write and there’s also the advib utility I actually deconstructed/reverse engineered on this this very site. I now feel like perhaps I have the knowledge and confidence I can go back and start trying to learn some of this stuff. And maybe not over-do it this time.

On the subject of that utility I wrote for my work I’ve actually been shopping some replacement technology/programming approach for a while there.

You see in the old days of 2000 – 2009 there was (still is really) this built-in windows technology called Windows Script Host (WSH) and later on to go along with it the HTML Application feature a.k.a. an HTA.

This HTA technology may have been ahead of its time: build a GUI using standard (IE standard) HTML, and CSS combined with the access to the internals of windows using WSH.

In other words, it’s possible to write an application indistinguishable from a normal application using CSS and HTML for the UI, and JScript or VBScript for functionality. Such an application could used do things like copy files, show available disk space and display an event log entry. The advantage (in my mind) being that this can be contained entirely in one text file, the source of which can be viewed and read as easily as the “view source” of any web page.

Well Microsoft stopped developing JScript and VBScript and the HTA version hasn’t changed since IE 8. But the functionality is still there. In fact the latest version of Hyper-V Server 2019 has a menuing system and utilities still written entirely in VBScript.

The utility I wrote for my work in 2011 or so still mostly works but doesn’t comprehend Windows 10 (as it didn’t exist at the time) and further trying to program in HTML and language(s) optimized for IE 8 is lets just say…not ideal. It did have the advantage of running on both Windows 7 and Windows 10, which has been kind of important in my work’s still mixed environment of 7 and 10. My work’s switch-over to Windows 10 will complete eventually probably.

It would be nice if something roughly equivalent had been made for PowerShell. Some kind of Edge-based equivalent of the HTA exe that could be tied directly to PS commands. But alas nothing like that was ever made.

As it turns out some like that was sort of made. It simply requires a little more than notepad to make it: PowerShell has the ability to import the XAML flavor of XML and produce GUI elements based on what is sees. Okay technically you can write XAML in a plain text editor if you wanted to. There just happens to be a more convenient alternative to designing the UI: Visual Studio Community edition.

If you’ve worked at all with HTML then XAML will look very, very familiar to you: the same sort of tags in blocks with descriptive attributes. But in Visual Studio there’s actually a place to drag-and-drop elements like buttons and text boxes and change their attributes and behavior without even editing the XAML text directly. The frustrating thing for me is how much storage space (not that I’m running out) and care has to go into installing Visual Studio just to get this UI designer/generator.

But at the end of all that is what I was actually looking for: a single text file with easily accessible source that can be opened with a text editor as simple as notepad. Although I haven’t yet figured out how to make the script run as easily as an HTA file yet I’m almost positive this is possible (though an “allow scripting” command may have to be set as a first step).

I was actually exploring multiple options. Like what is the difference between WPF and WinForms?

As it turns out I don’t know what the difference is. Except the UI designer seems a little different between the two and WPF seems much closer to the old school Visual Basic UI and designer (I mean back to VB6 ~20 years ago). They both seem to have VB and C# as language options and they both seem to have .NET runtime and .NET Core as variants. I think WinForms is the more recent version. Although C# is C# I assume.

I still have a lot learn in the whole .NET environment approach for what’s possible and the best way to do it. I think PowerShell has access to all or nearly all of the general APIs. Have to work on that.

So this is what I’m most looking forward to right now: re-designing a UI with new features and writing my work utility entirely in PowerShell. I would also like to re-do advib from scratch in a similar fashion.

I’ve about convinced myself I don’t actually have to know C# in order to write the events and get the remote PC information. I’ve been wrong about that sort of thing before. And I’ll probably stick to PS anyway.

I followed a WPF tutorial on youtube to get the basics. The resulting exe file was only a few Kilobytes.

If you’re wondering why that’s of note it’s because the other alternative technology I was looking at was with JavaScript with Node.js and a few options for the part that interacts with Windows APIs. Problem is even the simplest applications end up being multiple Megabytes because of the overhead of including an entire browser engine with each individual program.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s