May 28, 2009

Weighted Average

A simple script that allows you to take the average of two numbers... with a weight.

return (argument1-argument0)*argument2+argument0


Argument zero is the "small number", this should be considered your minimum, and is the result when you weight it to 0.
Argument one is the "big number", the result when you set the weight to 1, and also your "maximum".
Argument two is your weighted value, a percentage. Keep in mind that to calculate percents (Sorry if you already know this), the calculation is as follows: 100%/100=1, 50%/100=.5, 102.87%/100=1.0287. Simply push the decimal over. .5 is the average of the two numbers. (a+b)/2 It comes up with the number exactly between the two numbers.

Use this code to come up with different numbers between, based on a weight.
Uses I have discovered:

Graphics: A nice way to place a point between two points somewhere, I use it to place a point representing a stat, so if the best str you can have at level 1337 is 42, and you have 31 str, it would place the point closer to the 42 than to the 0.
Circles: Smooth turning for objects is possible with this code, by using the argument2 value as the dynamic, or changing, value. Smooth turning is easily accomplished, and looks good.
The obvious: You can use this to average.
Stats: If you want a weighted, maybe even linear, stat system, this is the one for you.

May 26, 2009

Game review day

Why? Because I can. I will now review a game that most of you out there have probably played, or at least heard of. "Pokemon Twilight".



I would rate this game, given the following categories (Graphics, Sound, Gameplay, Story, Bugs), a 3.4/5 star game. (Given that it's an awesome game, I'd rate it 5/5 without those categories.)

Graphics - 3.5/5
Sound - 3.5/5
Gameplay - 5/5 (For anyone who likes Pokemon)
Story - 2/5
Bugs - 3/5 (There're quite a few, and anyone who knows how, can use the testing cheats)

http://gameplague.com/games/62/PT.zip < This forums contains a download link, and communication with the game creators.

Until next time...

May 22, 2009

Alpha masks unveiled


To add an alpha mask to a sprite is actually quite simple, but the means of doing it isn't easy to find. The code is not in GM's help documentation at all: I checked. This code is...

sprite_set_alpha_from_sprite(ind,spr)


Now for actual usage, simply put the name of the sprite of the alpha mask (An example is shown above), in the second spot: "spr", put the image you want alpha masked in the first spot. Now draw the alpha masked sprite.

May 21, 2009

A simple rounding script

return round(argument0*power(10,argument1))/power(10,argument1)

Simply put, this code will allow you to round to however many decimal places you want. If this code were a script named 'rnd', for example:

rnd(10.15332,0)=10
rnd(10.15332,1)=10.2
rnd(10.15332,2)=10.15

And so on. Please make note of that decimal in the second argument make this script blow up in your face, and negative values will indeed round to numbers higher than the decimal point.
(rnd(13.539,-1)=10, for example)

May 15, 2009

Variable errors

A few variable errors will be mentioned today, including the above mentioned "Unknown variable" error.

The most common variable error you're going to get, most likely, is where you typo'd the variable name, in one way or another. For example:

Flea=0
woot=0
thatotherobjectoverthere.ex=0
pwnt=flea+wootr-ex

The above code, would throw an error if put into a completely blank GM game. Capitalization, spelling, and what object it is, are all important, and should be looked over carefully.

As for the unknown variable error, simply go to Global Game Settings, Errors, and check "Treat uninitialized variables as 0". This will fix that particular error, though you can still get bugs relating to variables. The above quote was also an example of an unknown variable error causer.

May 14, 2009

How to get rid of that division by 0 error

Hello, and welcome to this blog. This is for all those noobs at GM (Game Maker) who are getting started with coding. The division by zero error is known and hated by all, from Game Fortress to some random guy who uses Drag & Drop.

The division by zero error is the plague of all division problems. It's a rather simple fix, just make sure the number you divide by is never zero. (Accomplished by setting the variable to 1, or something else, in the create event, and not setting it to 0.)

If that is not possible, try this quick fix: (Note, this code was made for those beginning to use code, most people have learned it at one point or another, I'm simply publishing it.)

if [yourvariablehere]=0 //Check whether your denominator is 0.
then exit //This will leave the current chunk of code, be sure to put it at the end.
//alternatively to exit, you can use "then wewt=0".
else wewt=lol/[yourvariablehere] //Do the maths.


The above fix simply bypasses the math if the denominator is zero, you may want to replace exit with a code fix (Such as setting the variable to zero), as exit can cause other problems if used wrong.