Please login or register.

Login with username, password and session length
Advanced search  

News:

For WME related articles and tutorials visit WME Resource Center.

Author Topic: noob question about ChangeScene and variables  (Read 2906 times)

0 Members and 1 Guest are viewing this topic.

matthieuj

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 19
    • View Profile
noob question about ChangeScene and variables
« on: February 17, 2010, 10:10:15 PM »

Hello,
I was trying to understand how I could do a first-person game.
Here's my question : for one place, the character could look in always four directions (4 scenes?), and I was trying to do a "turn right" (or left) script working for any scene :
Imagine he's looking at :
scenes\Room1\place1\view-0.scene
with "turn right" he will look at
scenes\Room1\place1\view-1.scene
etc.
As my goal is to use a single script to do that from any scene, it should just take the end of the string and replace 0.scene by 1.scene etc. (+1 mod4) but I can't figure out how I can do this.
If someone was nice enough to give me a clue...
Thanks by advance and sorry for the stupid question.
Logged

metamorphium

  • Global Moderator
  • Addicted to WME forum
  • *
  • Karma: 12
  • Offline Offline
  • Gender: Male
  • Posts: 1511
  • Vampires!
    • View Profile
    • CBE  software s.r.o.
Re: noob question about ChangeScene and variables
« Reply #1 on: February 18, 2010, 09:02:12 AM »

Let's divide your ploblem in two parts:

1st you should define a template in Wme Dev kit Templates folder so you for your scenes always have 2 regions with 2 attached scripts defined (so you don't have to define them again and again for every single scene).

Now let's assume your scene will be named view-0.scene, your left turn view-1.scene and your right turn view-2.scene you can use the following mechanism (note that I am not around WME dev kit now so can't test the script) for the left turn:

Code: WME Script
  1. on "LeftClick"
  2. {
  3.    var SceneName = new String(Scene.FileName); // returns the filename of your current scene
  4.    var lng = SceneName.Length - 7; // we strip away the "0.scene" part
  5.    var newFile = SceneName.Substr(0,lng);
  6.    newFile = newFile + "1.scene";
  7.    Game.ChangeScene(newFile);
  8. }
  9.  

Hope this helps. This should at least get your started for potential solutions to your problem. :)

Logged
J.U.L.I.A. Enhanced Edition, Vampires!, J.U.L.I.A., J.U.L.I.A. Untold, Ghost in the Sheet

matthieuj

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 19
    • View Profile
Re: noob question about ChangeScene and variables
« Reply #2 on: February 18, 2010, 10:54:19 AM »

Thanks a lot Metamorphium! It was very helpful (and fast)!
Here's what I have done :

Code: [Select]
on "LeftClick"
{
  var SceneName = new String(Scene.Filename); // returns the filename of your current scene
  var lng = SceneName.Length - 7; // we strip away the "0.scene" part
  var number = SceneName.Substring(lng,lng);
  var newFile = SceneName.Substr(0,lng);
  number = ToInt(number) + 1;

if (number < 4){newFile = newFile + number + ".scene";}
  else {newFile = newFile + "0.scene";}
 
  Game.ChangeScene(newFile);
}
« Last Edit: February 18, 2010, 11:05:27 AM by matthieuj »
Logged
 

Page created in 0.042 seconds with 20 queries.