REFUCKTOR AHOYYYYYY

1) Code Repos and Versioning are not backup.

2) They are *especially* not backup if you forgot to commit your last good revision.

3) Especially if something weird was happening with your attempt to restore to what you thought was a previous decent version, but apparently it wasn’t so you wiped out a lot of your good work, like. almost 2 months worth (which, at the rate I go – is like – a day or two’s worth, still bites).

4) If you may recall, I was debating to use the “Scriptable Object” approach (I believe I posted that in my last entry) – this means, it’s now a perfect opportunity to do so.  More than I even thought before with my last post.

5) I’m not sure why but I’m intimidated.  I think it’s because while it’s clearly part of Unity and apparently an important part, and while there are documents and videos out there, there are not nearly as many posts/documents/videos on this issue as there are on many other simpler concepts.  I’m sure once I dig in, and run into problems, searches for specific solutions will arise and help out on that front.

6) So, even though I’m intimidated, I did do *something* today – though it wasn’t code (at least, not coding for my games – that other coding will be mentioned shortly)…  I ended up revamping how I’m drawing everything.  Previously it was a straight up 2D game.  The road was flat, it looked like vehicles were basically flat against the ride from the profile view.  This is fine for the basic idea and if I’m wanting to do something super quick, but since I’m doing a revamp and no longer in “48 hour gamejam” mode, I can take the time to fuck with this a bit more.  I’m still not going to be uber amazing at this, because I still want this to get out sooner rather than later (and boy it’s already later, but I think that’s sorta how development in general works: there’s always more to do, more you can do, and more you want to do).  I’m gonna upload a pic of the new style that I’m doing.  I’d *really* love to have a consistent set of 3D vehicles I could use, but that would require hiring an artist, with money I don’t have.  And there are assets out there, but as I said, “CONSISTENT”.  But I did download a whole bunch of other vehicle images and I’m going to just do my own art, instead of using the free bitmaps and stuff I’ve found online.  Regardless…  Here’s the little bit of rejiggering I did today – adding a z-axis/depth to the view, so you have depth perception, and instead of vehicles just being on top of each other, they pass behind one another now 🙂  Oh, and a little skyline added.  Perhaps each level I’ll add a different skyline or image, dunno yet.

 

DepthPerception summerjam2

 

The second thing is that my web-designer friend and I are working on a new project.  Nothing major, a sort of random grabber of pages in a directory – each of us will contribute various things to this cache of pages.  Might be images, might be video, might be a simple text page, might be something very complex… Links in the pages won’t go anywhere or do anything but grab more pages from this cache – you never know what you’ll find, there is no design of links or outside architecture.  In a sense, now that I think about it, it might be something one might be able to call a Non-deterministic Finite Automoton, though don’t quote me on that – I’m no computer scientist.

I’ve never used jQuery before, and I haven’t done any Javascript since the late 90s/early 00’s.  Most of my page stuff now is very simple and basic HTML, and any complex stuff I’ve saved for things like, you know, WordPress.

But I like to code, so I figured I’d do a little attempt at something and googled around for solutions and did my first thing which is a beeping “alarm” clock page.

The site is dopplegang.org (goes back to a highschool joke – and my current WoW guild);  So I made a dg visually that looks a little like LED clocks, and just have it blink in sync with the annoying alarm sound.

To do this I had to use jQuery (well I didn’t have to, but it seemed to be the easiest solution), and then I just set a blink rate.  I also centered it using jQuery (a friend pointed out it would have been a lot easier to just use tables, and I hate tables, so as much as jQuery annoyed me (which I’ll mention in a few), I still had fun learning about it and Javascript, linguistically – HTML tables, well, I’ve already done that, and I’d still have to look shit up and being that I kinda hate tables, I figure I learned more and had more fun with jQuery solution than the tables solution – even if tables would have been easier/quicker).

So I got to use anonymous functions (aka: lambdas) in Javascript for the first time.  I’m a big fan of functional programming, even if I don’t do enough of it myself, I love the theories behind it.  One of the essential features of functional programming (though not, by any means, the only feature) is the concept of lambda which can be seen as a function without a name.  What this means is you can write a bit of code inline for a one off use without needing to create a special function.  There are a lot of really cool things you can do with lambdas.  One thing is to basically bind a lambda function to a name (or, what we might call a “delegate”).  You can also bind non-lambda functions to another function or pass them as parameters to other functions (first-class functions is what we call this sort of ability – where the function that takes the other function as a parameter is called the “higher order” function).

Anyways, to do the jQuery code for centering my blinking image in the screen I ended up with a problem.  With the anonymous function, one of the tutorials had it set to load on window resize.  This meant that if a user resized their window, the centering of the image would also happen; otherwise the window would move but the image would stay in the same position relative to the original window, not the newly sized window.  This snippet/post by the person had you merely call “window.resize()” when you first load the page, which, in theory would then just trigger the centering function, but for whatever reason it didn’t work.

Another site mentioned using “onLoad()” (or whatever it’s called – I’m not a JS coder).  That worked fine for the first time I loaded the window, but not if I resized.

I was stumped.  How can I get it to load when I both load the window and resize the window? It would be patently ridiculous to create two separate functions that did the same thing to be called each time.  So this anonymous function was good, and what they’re having me do is good, but how in the bloody hell do I attach the lambda (what we call “binding”) to multiple functions to be called at the proper time?  Well there it was:

Line 6, the “$(window).on(‘load resize’…” code.  All you need to do is basically append each function name, to which you want to bind the lambda, onto this string that acts as, apparently, a parameter list… I don’t know how a list structure works in JS – though I had thought it would use commas to separate each element;  somehow it seems that it uses a space character to separate the function names – I’m not sure if that’s a jQuery thing or a JS thing.  Either way – it got the job done 🙂

Automute: Refactor? More like Refucktor.

Well, this is certainly something.

I started to try to refactor today.  Slowly moved over the methods from the LevelManager into the Level code so it was more localized.  It was kinda going well.  Got the vehicles working, but still had problems getting the levelSpeedMultiplier variable to actually set the vehicles speed.  I’m sure it’s some scoping issue.

In the process, I realized that I should move over some other methods, so proceeded to do that.  I thought I was having an “a ha!” moment (and I probably was, but my brain started getting all foggy so I took a nap)  After getting up, proceeded to do more damage.

All that’s left in the LevelManager right now is instantiating all the levelobjects inside the manager’s levelObjectArray.

Now I’m having issues with instantiation not properly being able to reset the values of something once it’s re-enabled.

What I had before was something like:

LevelManager.Instantiate(All Level Objects)

(none of these were actually active, as all the code to activate vehicles was being done in the levelmanager (which I think is really wrong, it should be from within the level itself — hence me shifting all the code around).

But because all the objects were active and never de-activated.  OK, I think I see what the issue is and it’s annoying and going to take a lot more work.

Once I reactivate a given object I have to reset all the values.  This is annoying because I already have it all setup perfectly.  Now if I have all the level objects in place and ready and only actually am working with a given levelobject from the levelmanager, then I’m fine.

So what I think I need to do is

Have the level manager set the current level object to active.

I should have an “alive” boolean on the level object, so long as all vehicles are in play, and when the vehicles are destroyed (via running off screen or by the player), they will then set the “alive” bool to false and send the message to the levelmanager to delete it and start the next level object up.

Now, since I will have to re-set all the values on each object, this is the annoying part.

I had an idea, but because my mind is so shot, I guess I think I’ll stop trying to think about it now and deal with it tomorrow.  Hopefully looking back at this post might remind me of what I was thinking when I started.  Ugh.

 

 

Automute: Refactoring and Hierarchy

Well I think I’ve mentioned needing to get to a refactoring soon, and it turns out this is a perfect point to do so.

I have been bashing my head this weekend trying to resolve an issue with accessing a value in the level object…

When I instantiate my vehicle, I use the iTween library to set it in motion across the screen.  Super easy.  I use the car’s “Speed” variable to tell it how fast to move.  I wanted to modify it’s speed based upon the level.  This means that I had speedModifier variable in the Level object that contained the set of vehicles it would be spawning.  In order to access this, I cached the level object in the car object.  In return this required me to cache the “levelManager” object.  If you are a programer you can probably already see how this is bad design.

But being that I’m not a good programmer (yet), and am still learning, it means that I didn’t catch this at the time.

I kept trying to access the levelSpeedModifier using multiple indirection through the levelmanager at the top, down into the level, and then call that in my iTween code in the vehicle.

In good OOP design, entities should really know as little about the outside world as possible.  My design broke that rule by requiring my vehicle to reach outside of itself to get this modifier.

Further, not only was it broken in that way, it literally was broken.  For whatever reason, I simply could not access the value in the level object, despite the fact I had made it public and that I set a “getter” property as well (I tried both ways).  When I set the value in the inspector, it clearly worked.  The reason I wasn’t doing that from the get go is because I wanted to be able to not worry about setting new values if I want to create new levels, the algo would take care of it for me and I could get to just writing more code/setting up more things than dick around in a separate editor to deal with making each and every level have it’s own unique component that may or may not relate to each other in any predictable way.  Certainly there’s a case to be made for doing it that way – that is one of the strengths of Unity after all.  But at this point, I was stumped.  I didn’t care that I could get around this issue by manually putting in this value for each level, I wanted to know why I couldn’t access it.

You may think this post will tell you the reason I wasn’t able to pull out this levelSpeedModifier variable from this higher level entity that existed as a unit in an array of level objects inside of a level manager…

I won’t.  Not because I don’t want to, but because, at this point, I don’t know.

Nor will I waste my time on trying to figure it out.  It may have a very good reason and I feel that I should understand the reason why, but I also understand part of the reason I’m having this issue in the first place is because I made the car require information on the outside world.

Nope, the proper way to do this would be to have the level (or levelmanager – I have to work out how it would really work) spawn the vehicle and set the vehicle move rate when it spawns the vehicle.  In this way, the car is all Honey Badger — “I don’t give a shit.  Just let me go, I got my maxSpeed, let me GO GO GO! ”

So, instead of trying to figure out why I can’t do this thing, I realize I shouldn’t even be worrying about why I can’t do this thing as it’s poor design, and since I’ve been meaning to refactor, now seems to be the perfect time to work on consolidation and encapsulation of my code.