I Wanna Community

Fangames => Game Design => Topic started by: l3agu32 on February 12, 2016, 01:29:25 PM

Title: How to save the kid's xscale?
Post by: l3agu32 on February 12, 2016, 01:29:25 PM
In the fangame I'm creating, when I press R the kid is always created facing the right (xscale=1), even if I shoot the save point facing the left (xscale=-1), how do I fix this? Thank you!
Title: Re: How to save the kid's xscale?
Post by: Kyir on February 12, 2016, 01:53:10 PM
just include player.image_xscale in the save and load scripts I'd guess? I think that would work at least.
Title: Re: How to save the kid's xscale?
Post by: patrickgh3 on February 12, 2016, 02:04:31 PM
I like to do this in my games as well. You'll need to modify the save file code to save and load an extra variable of whether the player's facing left or right.
Code: [Select]
Save script
/*save player x, y, room, etc */
file_bin_write_real(player.image_xscale+1)


Load Script
/* create player, load x, y, etc */
player.image_xscale = file_bin_read_real(file)-1

Simple enough. Be sure you add those lines in the same position relative to the other read and write functions. For simplicity it's probably best to add them at the end, after all the other reads / writes. And of course they belong before the file_bin_close lines; use common sense!

But wait, what are those mysterious "+1" and "-1"s doing there? Well, the player's xscale is going to be either 1 or -1, and the file_bin functions only write and read positive numbers. So, we add 1 so that the number we save is either 0 or 2, and when we load it we subtract back that 1.

So yeah, it's pretty simple to save extra stuff in save files. But xscale can be tricky because of that negative thing.

Edit: get rekt Kyir
Title: Re: How to save the kid's xscale?
Post by: Kyir on February 12, 2016, 02:07:10 PM
Hey, I didn't specify how to include it, so my advice is perfectly valid.