Please login or register.

Login with username, password and session length
Advanced search  

News:

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

Pages: [1] 2  All

Author Topic: The right sequence will open the door...  (Read 10144 times)

0 Members and 1 Guest are viewing this topic.

The Man

  • Occasional poster
  • **
  • Karma: 1
  • Offline Offline
  • Posts: 67
    • View Profile
The right sequence will open the door...
« on: April 26, 2008, 04:58:54 PM »

I'll try to explain myself the best I can...
I have this first person scene in which you can see a bookcase.In this bookcase there are four interactive books,that must be pressed in a certain sequence in order to open a door.If a book is pressed,it plays an animation.After You pressed all four books,the program should check if they have been pressed in the right sequence,and if not,the player must be able to start again from the beginning.
What's the best way to do this?I think I have to use arrays in some way,but I dont' know exactly how to...
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: The right sequence will open the door...
« Reply #1 on: April 28, 2008, 01:27:12 PM »

Here's how I would do that... Use a string variable. Name the books like "1", "2", "3" etc. Everytime you click the book, add its name to the string variable and check if the length of the string is equal to the number of books. If it is, check if the string equals to the correct book combination. If it is, you're all set. If not, empty the string variable and start over.
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

The Man

  • Occasional poster
  • **
  • Karma: 1
  • Offline Offline
  • Posts: 67
    • View Profile
Re: The right sequence will open the door...
« Reply #2 on: April 28, 2008, 05:00:00 PM »

I understand,but what's the command to check the lenght of a string?
Logged

Net

  • Gripped Software Programmer
  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 48
    • View Profile
    • Čurina
Re: The right sequence will open the door...
« Reply #3 on: April 28, 2008, 07:19:02 PM »

Code: [Select]
var test;
test = "Some text";

Game.Msg(test.Length); //this produce number 9 (strings SOME TEXT length)
« Last Edit: April 29, 2008, 08:53:12 AM by Net »
Logged

The Man

  • Occasional poster
  • **
  • Karma: 1
  • Offline Offline
  • Posts: 67
    • View Profile
Re: The right sequence will open the door...
« Reply #4 on: April 29, 2008, 05:46:59 PM »

So I have to write something like:

if(a.length=4 && a=1342)
{
/do something/
}

Where "a" is my string variable,"4" is the number of books and "1342" is the right combination.
Is it correct?If not,how do I write this?
Logged

Net

  • Gripped Software Programmer
  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 48
    • View Profile
    • Čurina
Re: The right sequence will open the door...
« Reply #5 on: April 29, 2008, 07:11:39 PM »

Code: [Select]
if(a.length=4 && a=1342) <-- there is a mistake
{
/do something/
}

if you use = you will set the variable
to check you must use ==

so your code must look like

Code: [Select]
if(a.length==4 && a==1342)
{
/do something/
}

and ofcourse you must add the numbers to your string variable this way

Code: [Select]
a = a + "NUMBER";

else you will sum the numbers and then your code

Code: [Select]
/do something/
will never be done
Logged

The Man

  • Occasional poster
  • **
  • Karma: 1
  • Offline Offline
  • Posts: 67
    • View Profile
Re: The right sequence will open the door...
« Reply #6 on: April 29, 2008, 08:24:42 PM »

Argh...I don't know,it doesn't work...Can you please check if there are mistakes?
I wrote this code into scene_init.script:

Code: [Select]
global a;
a = new String()256;
a="";

if(a=="1212")
{
Game.Msg("You did it!");
}

Then in the first book script I wrote:

Code: [Select]
global a;
on "LeftClick"
{
 a=a + "1";
}

And finally in the second book script:

Code: [Select]
global a;
on "LeftClick"
{
 a=a + "2";
}

So when I click the books in the sequence "first,second,first,second" The game should write "You did it!",but nothing happens instead...
Logged

Net

  • Gripped Software Programmer
  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 48
    • View Profile
    • Čurina
Re: The right sequence will open the door...
« Reply #7 on: April 29, 2008, 08:44:02 PM »

Code: [Select]
a = new String()256; <-- here

the right way is

Code: [Select]
a = new String(256);
Logged

The Man

  • Occasional poster
  • **
  • Karma: 1
  • Offline Offline
  • Posts: 67
    • View Profile
Re: The right sequence will open the door...
« Reply #8 on: April 29, 2008, 08:50:16 PM »

Sorry,I wrote it in the wrong way here in the forum...in my script I wrote it in the right way,but still doesn't work...
I'm becoming crazy looking at these scripts...
Logged

Net

  • Gripped Software Programmer
  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 48
    • View Profile
    • Čurina
Re: The right sequence will open the door...
« Reply #9 on: April 29, 2008, 09:43:39 PM »

Nevermind.
Is there any error?
« Last Edit: April 29, 2008, 10:00:20 PM by Net »
Logged

rkitting

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 44
    • View Profile
Re: The right sequence will open the door...
« Reply #10 on: April 30, 2008, 08:21:30 AM »

What errors are you getting in your wme.log file?
Logged

The Man

  • Occasional poster
  • **
  • Karma: 1
  • Offline Offline
  • Posts: 67
    • View Profile
Re: The right sequence will open the door...
« Reply #11 on: April 30, 2008, 08:54:52 AM »

This is another strange thing...I'm not getting any error...it looks like everything works fine,but the code isn't executed...
How would you program this kind of code?Am I the only one who has got this kind of problem?
Logged

Net

  • Gripped Software Programmer
  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 48
    • View Profile
    • Čurina
Re: The right sequence will open the door...
« Reply #12 on: April 30, 2008, 09:35:45 AM »

scene_init script is executed ONLY when you enter the scene and then it ends.

Try in scene_init script write this:

Code: [Select]
while(true)
{
  if(a=="1212")
  {
    Game.Msg("You did it!");
  }
  Sleep(200);
}
Logged

The Man

  • Occasional poster
  • **
  • Karma: 1
  • Offline Offline
  • Posts: 67
    • View Profile
Re: The right sequence will open the door...
« Reply #13 on: April 30, 2008, 10:16:21 AM »

Ok,that worked,but that was a try....Now I tried to adapt the code to my needs and wrote this:

Code: [Select]
global a;
a = new String(256);
a="";


while(true)
{
 if(a.Length==4 && a=="1212")
    {
  Game.Msg("You did it!");
    }

Sleep(200);
}

while(true)
{
  if(a.Length==4 && a!="1212")
    {
Game.Msg("You failed!");
    }
Sleep(200);
}

I thought this would have worked,instead the right combination works and the game writes "You did it!" but the wrong combinations doesn't do anything...I dont' know,it looks like the program doesn't read "a.Length"...maybe I'm using it in the wrong way... Also,I should add some command in the second "while" branch,that reset my "a" variable,but I dont' know exactly How's this command like...
Logged

Net

  • Gripped Software Programmer
  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 48
    • View Profile
    • Čurina
Re: The right sequence will open the door...
« Reply #14 on: April 30, 2008, 10:53:26 AM »

You don't have to double use while(true).

This should work as you expect

Code: [Select]
while(true)
{
  if (a.Length == 4)
  {
    if (a == "1212")
    {
      Game.Msg("You did it!");
    }
    else
    {
      Game.Msg("You failed!");
    }
  }
  Sleep(200);
}

I rewrote your code, because if you use

Code: [Select]
while(true)
{
  if(a.Length==4 && a=="1212")
  {
    Game.Msg("You did it!");
  }
  else
  {
    Game.Msg("You failed!");
  }
  Sleep(200);
}

the game will write You failed! every time the loop is executed. The first (I think working code) will check, if variable a has length 4 and then check its value and write You did it! or You failed!. If variable a doesn't have expected length, the inner code will not be executed.

I hope this will help and I'm sorry for my English.
Logged
Pages: [1] 2  All
 

Page created in 0.02 seconds with 19 queries.