Log in

No account? Create an account
Previous Entry Share Next Entry

Total Esoteric Game Crap

So I messing around with Twine, trying to figure out how to work the skill system.

You've got skills that display on the sidebar. (Well, I made them display on the sidebar.) Each skill is represented as a variable: $skill

But if you simply increase by a point every time you do something--say your $hunter skill increases by 1 every time you poke a hamster with the Pointy Stick--you are going to level really really really fast and everybody's going to be level 80 before they're bored. And if hamsters are worth 1, then a mammoth ought to be worth, what--10? 20? A MILLION?

If poking a hamster is not worth 1, though--say it's only worth .1, or .2 or whatever--then your sidebar is gonna be all "Hunter: 37.822" and that's inelegant as hell.

So I get this idea--I will make a hidden variable! I can do that! I will make $hidden_hunter and it will go up by 1 when you poke the hamster and 10 when you poke the mammoth, and whenever it gets to 10, your $hunter skill goes up by 1 and the $hidden_hunter skill decreases by 10 (so that if you were at 3 when you poked the mammoth, you wouldn't lose the extra points in the rounding down.)

And furthermore, because there is a handy function called visited() that tracks how many times a player has visited a particular "room" (I'm thinking of them as rooms--the node map looks like an old-style dungeon crawl) I can set the whole deal so that if you have stood over the body of 10 dead hamsters, you are done learning about hamsters and no longer derive benefit from poking them.

I was very proud of this.

It is probably quite inelegant and there is some crap I should be doing with objects or Javascript or god only knows what, but y'know, for basically having the code skills of kelp, I was rather proud of myself for having solved the problem this way.

Even Kevin admitted that it was impressive--at least, that I'd come up with it, not that it was a great solution, although he did not propose a better one and only muttered something about objects and told me to go write my hamster poking commands and he would see what he could do to make it easier to work with. And undoubtedly all you code monkeys at home are going "But you could just do this thing. Once. Over there. And then it would handle it FOREVER."

But seriously, for me? This crap is rocket science. I'm gonna sit here and be smug for a least five minutes, or until everything else in the game breaks.

Hooray for hidden variables! And having fun breaking things. (This feeling of triumph is why people get into programming and its ilk, and why I have not collapsed in weeping tears at the helpdesk for giving us such a crappy email system to work with, because I get to troubleshoot it as well as use it...)

I'm pretty sure this is exactly how the process of learning a new skill is meant to work. You bumble around, discover some things that work and some things that don't, use the skills you've developed so far to approximate the best solution that you can, and improve in the process. The fact that you came up with something that works means that you're doing it right, and next time it'll be a little bit easier because you've already found one way to solve a problem within this system...and each time you find and resolve another problem, you're learning more and more about what does and doesn't work. Who cares about efficiency? You're learning, and that's awesome!

Except that as you learn the new skill, simple problems get far too simple to teach you anything, and the world starts delivering the mammoth sized problems that you need to be able to continue learning, and that's how you end up leaning over the ticking device that will explode the planet in the next 10 seconds if you don't remember whether it's the blue wire or the mauve one that you're supposed to cut...

Or one could just stay home and play Minesweeper...

I think I would simply lop off decimals in displaying instead, if the system allows for that.

So while the system retains actual the value of $hunter, whenever it needs to show $hunter to player, it "rounds down" right after the decimal point. I'm not a good coder, I just do PHP, but check out if round() function is available for you.

However, congratulations on your steps to learning! I still remember when I started with PHP myself. :)

I looked this up. You can in fact round numbers for printing:

It's got <<print Math.round(Math.random() * 6)>> bullets.

But I think ursulav's solution of having the major skill level up when the hidden skill reaches some number is better because otherwise you might see:

"Your Hunter skill has increased to 6!"

"But wait, it was already 6..."

"Well, it went up by a decimal place, but I rounded it..."

"Dude. You are confusing me."

How about having the visible variable be the log of the hidden variable. So you poke the hamster once, your skill goes up straight away. Poke it several more times, you get a bit more skill. But after that, it takes forever to get further. Poke a mammoth - zowie. But keep poking it, you don't learn much more. Till you poke the dragon.

You actually pretty much nailed the way it works in RPG games. :) (Feel free to rationalize it as all those hours of playing games finally paying off; I know I would totally do it.)

Usually there is an additional variable, let's call it $level_up_threshold, which goes up every time you level up. In your example, that variable kind of exists and is always set to 10 (so you essentially got that right too). The point of increasing it as you level up is so you don't keep leveling up faster and faster as you tackle bigger monsters later in the game.

That said, you don't get to also become awesome at algorithms. Leave the rest of us something to feel worthy about, nyah.

I love this solution!

As an aside, yesterday a friend posted this:

99 little bugs in the code
99 little bugs
Take one down, patch it around,
127 little bugs in the code!

When you bug count comes back as -NAN (negative Not A Number) you have officially done something bad and should stop and think about what you have done. Preferably with an alcoholic beverage in hand.

(no subject) (Anonymous) Expand
Congrats on your rocket science! :D

That's totally earned smugness. Go you!

Go you!

Programming is an art, and just like any art it takes practice. Which usually includes breaking things and making spectacular messes.

Do use a version control system (I recommend git, but YMMV) -- it makes it a lot easier to get things back to the last place where they worked.

Actually, Neverwinter, the D&D freebie game that I play pretty much does it that way. You get Experiance points for doing something, and when they hit max, you level up. So $_variabeXP goes up by one point or whatever, and when that maxes out, $_VariableLevel increments by one. Pretty much the same thing, only not hidden.

This is actually making me want to mess around with Twine too. That sounds like a lot of fun.

Look, my spouse is messing around with making an RPG character-sheet generator in Apple's Numbers or whatever it's called, and was all annoyed that the code-language wouldn't let him do , and then gleeful about being able to overlay cells over each other, then turn the "background" cells to 1-point type (which makes them effectively invisible), so he could get around the limitations of the coding language.

And this is a guy who's been programming over 30 years.

Which is to say, your solution sounds fine to me.

Nice! How are you handling storing the information...if at all? Meaning, if someone leaves the page halfway through the game are you somehow storing their progress? The only solution I've found so far seems to be based on browser history which is...clunky at best. I'm sure someone more clever could figure out how to involve a database but that person is not me, alas.

That's one of my current concerns, actually--trying to figure out how to save people's places, their stats, and what happens when I need to release an update. (There's no point in having people play Act One if they get zeroed out when it goes to Act Two...or every time I have to upload a bug fix!)

(Deleted comment)
...Look! I have a save game function! It has cookies! Or runs on cookies! Or something!

(Uh, this is over esoteric for me. There are two ways to play Twine games, I think--one to download them and play locally, one to play them online. I think the game is saved locally. It's a variation on something called "Tiddlywiki," I think?)

(Deleted comment)
I'm very proud to see you've begun your journey into mastering hamster-oriented programming. With years of dedication, we may let you work with rabbits.