Author Topic: How to save the kid's xscale?  (Read 1347 times)

l3agu32

  • Wannabe
  • Posts: 22
  • OS:
  • Windows 8.1/Server 2012 Windows 8.1/Server 2012
  • Browser:
  • Chrome 48.0.2564.109 Chrome 48.0.2564.109
    • View Profile
  • Playstyle: Keyboard
How to save the kid's xscale?
« 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!

Kyir

  • The Kid
  • Posts: 293
  • Normal Guy
  • OS:
  • Windows 7/Server 2008 R2 Windows 7/Server 2008 R2
  • Browser:
  • Chrome 48.0.2564.109 Chrome 48.0.2564.109
    • View Profile
  • Playstyle: Keyboard
Re: How to save the kid's xscale?
« Reply #1 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.
« Last Edit: February 12, 2016, 01:57:46 PM by Kyir »

patrickgh3

  • Spike Dodger
  • Posts: 169
  • stay optimistic! :D
  • OS:
  • Windows 10 Windows 10
  • Browser:
  • Firefox 44.0 Firefox 44.0
    • View Profile
    • Github
  • Playstyle: Keyboard
Re: How to save the kid's xscale?
« Reply #2 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

Kyir

  • The Kid
  • Posts: 293
  • Normal Guy
  • OS:
  • Windows 7/Server 2008 R2 Windows 7/Server 2008 R2
  • Browser:
  • Chrome 48.0.2564.109 Chrome 48.0.2564.109
    • View Profile
  • Playstyle: Keyboard
Re: How to save the kid's xscale?
« Reply #3 on: February 12, 2016, 02:07:10 PM »
Hey, I didn't specify how to include it, so my advice is perfectly valid.
« Last Edit: February 12, 2016, 02:10:30 PM by Kyir »