Please login or register.

Login with username, password and session length
Advanced search  

News:

IRC channel - server: waelisch.de  channel: #wme (read more)

Author Topic: Problem with saving X & Y coordinates  (Read 4380 times)

0 Members and 1 Guest are viewing this topic.

maze

  • Occasional poster
  • **
  • Karma: 0
  • Offline Offline
  • Posts: 59
  • Good news
    • View Profile
Problem with saving X & Y coordinates
« on: July 11, 2007, 10:33:31 AM »

Hi Guy's,

I want't to save the X and Y Position of some entities, for a recall after a scene change.

I write it in global's like this: 
Code: [Select]
save_blue1X = (blue1.X);And recall it like this: 
Code: [Select]
blue1.SkipTo(save_blue1X, save_blue1Y);
It work's fine, but after I change the scene two times, in my save-global's is a null and all my entities are in the leftup border from the screen.

Thx

Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: Problem with saving X & Y coordinates
« Reply #1 on: July 11, 2007, 10:48:19 AM »

Where exactly did you put these lines?
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

maze

  • Occasional poster
  • **
  • Karma: 0
  • Offline Offline
  • Posts: 59
  • Good news
    • View Profile
Re: Problem with saving X & Y coordinates
« Reply #2 on: July 11, 2007, 10:55:33 AM »

I give you the two scripts

Saving:
Code: [Select]
#include "scripts\base.inc"
#include "scripts\keys.inc"
#include "scripts\puzzle.inc"

var yellow1 = Scene.GetNode("yellow1");
var yellow2 = Scene.GetNode("yellow2");
var yellow3 = Scene.GetNode("yellow3");
var blue1 = Scene.GetNode("blue1");
var blue2 = Scene.GetNode("blue2");
var blue3 = Scene.GetNode("blue3");

on "Keypress"
{if(Keyboard.KeyCode==VK_F5 || Keyboard.KeyCode==VK_F5)
   
{save_yellow1X = (yellow1.X); // save the peg position's
save_yellow1Y = (yellow1.Y);
save_yellow2X = (yellow2.X);
save_yellow2Y = (yellow2.Y);
save_yellow3X = (yellow3.X);
save_yellow3Y = (yellow3.Y);
save_blue1X = (blue1.X);
save_blue1Y = (blue1.Y);
save_blue2X = (blue2.X);
save_blue2Y = (blue2.Y);
save_blue3X = (blue3.X);
save_blue3Y = (blue3.Y);
Game.ChangeScene("scenes/options/options.scene"); // and load the options menu
    }
   
}
and loading:
Code: [Select]
#include "scripts\base.inc"
#include "scripts\puzzle.inc"


// here comes the stuff which initializes the scene
actor.Active = false;

// get the peg's from scene
var yellow1 = Scene.GetNode("yellow1");
var yellow2 = Scene.GetNode("yellow2");
var yellow3 = Scene.GetNode("yellow3");
var blue1 = Scene.GetNode("blue1");
var blue2 = Scene.GetNode("blue2");
var blue3 = Scene.GetNode("blue3");



if(Game.PrevScene=="options") // if we came back from options
{ yellow1.SkipTo(save_yellow1X, save_yellow1Y);
  yellow2.SkipTo(save_yellow2X, save_yellow2Y);
  yellow3.SkipTo(save_yellow3X, save_yellow3Y);
  blue1.SkipTo(save_blue1X, save_blue1Y);
  blue2.SkipTo(save_blue2X, save_blue2Y);
  blue3.SkipTo(save_blue3X, save_blue3Y);      // recover the peg's placement
 
  if (yellow1_selected == true) yellow1.PlayAnimAsync("scenes\puzzle\sprites\yellow_sel.sprite");
  if (yellow2_selected == true) yellow2.PlayAnimAsync("scenes\puzzle\sprites\yellow_sel.sprite");
  if (yellow3_selected == true) yellow3.PlayAnimAsync("scenes\puzzle\sprites\yellow_sel.sprite");
  if (blue1_selected == true) blue1.PlayAnimAsync("scenes\puzzle\sprites\blue_sel.sprite");
  if (blue2_selected == true) blue2.PlayAnimAsync("scenes\puzzle\sprites\blue_sel.sprite");
  if (blue3_selected == true) blue3.PlayAnimAsync("scenes\puzzle\sprites\blue_sel.sprite"); // recover selected peg
}

else // Init a new game
{
// peg's are not selected
yellow1_selected = false;
yellow2_selected = false;
yellow3_selected = false;
blue1_selected = false;
blue2_selected = false;
blue3_selected = false;

// peg placement
state_yellow1 = 1;
state_yellow2 = 2;
state_yellow3 = 3;
state_blue1 = 6;
state_blue2 = 7;
state_blue3 = 8;

// field's states
state_1 = true; // occupied
state_2 = true; // occupied
state_3 = true; // occupied
state_4 = false;// free
state_5 = false;// free
state_6 = true; // occupied
state_7 = true; // occupied
state_8 = true; // occupied
}


// load options
Game.AttachScript("scripts/options.script");

////////////////////////////////////////////////////////////////////////////////
// scene state
global Statepuzzle;


// default values
if(Statepuzzle==null)
{
  Statepuzzle.Visited = false;
  // add scene states here
}



////////////////////////////////////////////////////////////////////////////////
// setup scene according to state variables



////////////////////////////////////////////////////////////////////////////////
if(!Statepuzzle.Visited)
{
  Statepuzzle.Visited = true;

  // this is our first visit in this scene...
  music_on = true;
  sound_on = true;
  music_vol = 70;

}

////////////////////////////////////////////////////////////////////////////////
// Some music
if(music_on == true)
{Game.SetGlobalMusicVolume(music_vol);  // volume
if(!Game.IsMusicPlaying())  //if music is already playing, game wouldend start it new
{
Game.PlayMusic("music\bongobongo.ogg");
}
}
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: Problem with saving X & Y coordinates
« Reply #3 on: July 11, 2007, 12:17:02 PM »

And the save_yellowXX are global variables declared somewhere..? You aren't assigning them some value anywhere else, are you?
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

maze

  • Occasional poster
  • **
  • Karma: 0
  • Offline Offline
  • Posts: 59
  • Good news
    • View Profile
Re: Problem with saving X & Y coordinates
« Reply #4 on: July 11, 2007, 01:07:17 PM »

Yes, they are declared at the puzzle.inc and I used them only in this two scripts.

Could it be cause the save-script is attached in the load script(scene_init)?

Maybe it's no big problem, cause I'm not very experienced with your wme, the only scripting languages I normaly use are for machine's.
If you want, I'll send you the whole project file.

Thanks for wasting time with me.



Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: Problem with saving X & Y coordinates
« Reply #5 on: July 11, 2007, 01:10:12 PM »

If you want, I'll send you the whole project file.
If you could, it would be helpful, because I can't see anything obviously wrong with the code.
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: Problem with saving X & Y coordinates
« Reply #6 on: July 11, 2007, 04:36:51 PM »

Ah, got it. The F5 code should look like this:

Code: WME Script
  1. #include "scripts\base.inc"
  2. #include "scripts\keys.inc"
  3. #include "scripts\puzzle.inc"
  4.  
  5. on "Keypress"
  6. {
  7.   if(Keyboard.KeyCode==VK_F5 || Keyboard.KeyCode==VK_F5)   
  8.   {
  9.     var yellow1 = Scene.GetNode("yellow1");
  10.     var yellow2 = Scene.GetNode("yellow2");
  11.     var yellow3 = Scene.GetNode("yellow3");
  12.     var blue1 = Scene.GetNode("blue1");
  13.     var blue2 = Scene.GetNode("blue2");
  14.     var blue3 = Scene.GetNode("blue3");
  15.  
  16.     save_yellow1X = (yellow1.X);        // save the peg position's
  17.     save_yellow1Y = (yellow1.Y);
  18.     save_yellow2X = (yellow2.X);
  19.     save_yellow2Y = (yellow2.Y);
  20.     save_yellow3X = (yellow3.X);
  21.     save_yellow3Y = (yellow3.Y);
  22.     save_blue1X = (blue1.X);
  23.     save_blue1Y = (blue1.Y);
  24.     save_blue2X = (blue2.X);
  25.     save_blue2Y = (blue2.Y);
  26.     save_blue3X = (blue3.X);
  27.     save_blue3Y = (blue3.Y);
  28.     Game.ChangeScene("scenes/options/options.scene"); // and load the options menu
  29.   }   
  30. }
  31.  

That is, you need to query the scene entities before checking their properties.

In your code, you fill the yellow1-3 and blue1-3 variables with entities. That's fine. You remember their positions. Also fine. You change scene, the entities get destroyed. But once they're destroyed, WME also automatically invalidates your variables (they'd be referencing non-exisisting entities).
Now you return back from the menu, a new set of entities is created. But when you press F5 for the second time, you're still using the old invalidated variables. That's why you get 'null' when reading their positions.
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

maze

  • Occasional poster
  • **
  • Karma: 0
  • Offline Offline
  • Posts: 59
  • Good news
    • View Profile
Re: Problem with saving X & Y coordinates
« Reply #7 on: July 11, 2007, 05:08:34 PM »

 :o Thanx to the king of code.
I'll never figure this out by myself.
It's good to know, now I understand wme a little bit more.
Once this little game is finished, I'll give it to the wme community as open source, but I think this will take a while.
Did you like it, or is it terrible circular coded?
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: Problem with saving X & Y coordinates
« Reply #8 on: July 12, 2007, 07:35:07 AM »

I liked what I saw, but frankly I didn't have the time to check it thoroughly :)
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave
 

Page created in 0.284 seconds with 25 queries.