Please login or register.

Login with username, password and session length
Advanced search  

News:

Latest WME version: WME 1.9.1 (January 1st, 2010) - download

Author Topic: Scripting help - declaring variables  (Read 4279 times)

0 Members and 1 Guest are viewing this topic.

Pelrock

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 13
    • View Profile
Scripting help - declaring variables
« on: December 23, 2011, 01:52:56 AM »

Hi all,

It´s been a long time since the last time I posted something on the forum. I have just downloaded the last version of Wintermute, and I have to say, really, congratulations for this outstanding piece of software. My grattitude forever, Mnemonic.

I´m having some issues developing the script of my game, as I haven't got much knowledge of programming. I reached a point where things are not behaving as expected... if someone could help me out, here´s my question:

I´ve got this script structure (it´s an example of one of many I have already in the game):

////////////////////

Code: WME Script
  1. [code=script][code=script]global myvariable
  2.  
  3. function actorDialogue()
  4. {
  5.         if (myvariable == 0)
  6.         {
  7.            actorDialogue1();
  8.         }
  9.         else if (myvariable == 1)
  10.         {
  11.                actor.Talk("Hello World");
  12.                actorDialogue2();
  13.         }
  14.         else if (myvariable == 2)
  15.         {
  16.                actor.Talk("Hello again");
  17.                actorDialogue3();
  18.         }
  19.         else if (myvariable == 3)
  20.         {
  21.                actor.Talk("At last!");
  22.                actorDialogue4();
  23.         }
  24.         else if (myvariable == 4)
  25.         {
  26.                actor.Talk("The End");
  27.              
  28.         }
  29. }
  30.  
[/code][/code]


///////////////////////////////////////////////////

The variable I have declared is working in every case, it is being change by another character of the game, after a couple of actions (myvariable = 1, myvariable =2, etc) except for the last one, when is equal to 4.

Is there a limitation of 3? or is there something that I did wrong?
As I said, my knowledge of programming is very poor, so I assume there must be an easy way to approach this kind of things...
If anyone can help me I woul apprectiate it, thanks a lot.
Logged

ahedov

  • Lurker
  • *
  • Karma: 2
  • Offline Offline
  • Posts: 29
    • View Profile
Re: Scripting help - declaring variables
« Reply #1 on: December 23, 2011, 12:16:24 PM »

Maybe switch-case declaration will be more appropriate.

Code: [Select]
switch (Color)
{
  case "black":
    actor.Talk("Creepy");
  break;

  case "red":
    actor.Talk("Cheerful");
  break;

  case "yellow":
    actor.Talk("Bright");
  break;

  default:
    actor.Talk("Neutral");
}
Logged

Pelrock

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 13
    • View Profile
Re: Scripting help - declaring variables
« Reply #2 on: December 23, 2011, 12:53:41 PM »

Hi, thanks for the response. I didn´t know that one.
But I am not sure if that can be applied to this case...

I´d like the "Actor A" make different actions within the game that changes the value of "myvariable". So when he talks to "Actor B" the dialogue lines to choose are different.

For example, Actor A talks to Actor B, he tells him to pick up one ingredient for a soup. He finds the first one and now "myvariable = 1", then he comes back  to speak with actor B and the dialogue is different, he has now different options to choose.

I did that and it seems to work until "myvariable" equals to 4...

Do you know a better way to do this? can I do it the way you told me?

Logged

ahedov

  • Lurker
  • *
  • Karma: 2
  • Offline Offline
  • Posts: 29
    • View Profile
Re: Scripting help - declaring variables
« Reply #3 on: December 23, 2011, 01:52:11 PM »

If I were you, I would try this:

Code: WME Script
  1. global myVariable;
  2.  
  3. //some action changes myVariable to 1
  4. myVariable = 1;
  5.  
  6. //some other action changes myVariable to 2
  7. myVariable = 2;
  8.  
  9. //trigger the function actorDialogue
  10. actorDialogue(myVariable);
  11.  
  12. //function actorDialogue with parameter
  13. function actorDialogue(myVar)
  14. {
  15.       switch (myVar)
  16.       {
  17.         case 1:
  18.           actor.Talk("First line.");
  19.           actorDialogue1();
  20.           break;
  21.         case 2:
  22.           actor.Talk("Second line.");
  23.           actorDialogue2();
  24.           break;
  25.         case 3:
  26.           actor.Talk("Third line.");
  27.           actorDialogue3();
  28.           break;
  29.          
  30.           //etc.
  31.       }
  32. }
  33.  
« Last Edit: December 23, 2011, 01:53:57 PM by ahedov »
Logged

Pelrock

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 13
    • View Profile
Re: Scripting help - declaring variables
« Reply #4 on: December 23, 2011, 03:14:31 PM »

That´s fantastic. Thank you very much for that, I will try it soon and I let you know.

Cheers!
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: Scripting help - declaring variables
« Reply #5 on: December 23, 2011, 06:33:32 PM »

However, your original script should work as well. At least I can't see anything wrong with it (except a missing semicolon after "global myvariable").
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

Pelrock

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 13
    • View Profile
Re: Scripting help - declaring variables
« Reply #6 on: December 26, 2011, 02:30:47 PM »

Hi, thanks for your help!

Yes, I actually changed the structure but the result was the same, and I had the same error again.

But it helped me to find the problem. I had the same variable changing the same value in another script and I always returned to state 3 after making that action...

The good thing is that I finally got out of the loop and I could move forward a little bit on the script.
Many thanks
Logged
 

Page created in 0.062 seconds with 21 queries.