Script problem again!

Topics regarding Scripting with Reality Factory
Post Reply
User avatar
GMer
Posts: 329
Joined: Thu Oct 25, 2007 4:49 pm
Location: On the rock in the 3rd solar orbit.

Script problem again!

Post by GMer »

Here is a script I am using:

Code: Select all

{
   INCREASETIMER   [0]
   TIMERAMOUT      [0.5]

   Spawn[ ()
   {
      Console(true);
      LowLevel("Keycheck");
   } ]

   Keycheck[ ()
   {
      if(INCREASETIMER < self.time)
      {
         if (GetAttribute("health","Player") < 30)
         {
            PlaySound("healthlow.wav");
         }
         else
         {
	    PlaySound("silent.wav");;
         }
         INCREASETIMER = self.time + StringCopy(TIMERAMOUT);
      }
      debug(GetAttribute("INCREASETIMER", "HC"));
   } ]
}
When I start reality factory, it crashes. Basically this sucker is supposed to play "healthlow.wav" when the player's health is lower than 30.
Over 3 years (has it been that long?) and just now I noticed the day and month of my birthday were switched. Whoops!

Some 2d games I made, haven't made anything in a year though O.o
http://www.yoyogames.com/users/GMer56
User avatar
Juutis
Posts: 1511
Joined: Thu Jan 12, 2006 12:46 pm
Location: Finland

Re: Script problem again!

Post by Juutis »

PlaySound("silent.wav");;
Pain is only psychological.
User avatar
metal_head
Posts: 1244
Joined: Sat Jan 05, 2008 8:31 pm
Location: Bulgaria,Sofia
Contact:

Re: Script problem again!

Post by metal_head »

But than if the player's health goes bellow 30, the sound will be played every frame :X Is that what you wanted to have or you just wanna play it once?
User avatar
GMer
Posts: 329
Joined: Thu Oct 25, 2007 4:49 pm
Location: On the rock in the 3rd solar orbit.

Re: Script problem again!

Post by GMer »

When the sound stops, I want it to play again (if the player's health is under 30), which is why there is the "INCREASETIMER" variable. I have gotten the script to play when I hold down space, but not with this script.
Now that was a stupid mistake on my part :lol: . Thanks, Juutis!
Over 3 years (has it been that long?) and just now I noticed the day and month of my birthday were switched. Whoops!

Some 2d games I made, haven't made anything in a year though O.o
http://www.yoyogames.com/users/GMer56
User avatar
jonas
Posts: 779
Joined: Tue Jul 05, 2005 5:43 pm
Location: Texas, USA
Contact:

Re: Script problem again!

Post by jonas »

Don't you love that? :D You look at it over and over, then someone else looks at it once and sees it. Always makes me feel like a genius. :lol: Good thing we have our screens to hide behind. :mrgreen:
Jonas

Focused, hard work is the real key to success. Keep your eyes on the goal, and just keep taking the next step towards completing it. If you aren't sure which way to do something, do it both ways and see which works better. - John Carmack
User avatar
metal_head
Posts: 1244
Joined: Sat Jan 05, 2008 8:31 pm
Location: Bulgaria,Sofia
Contact:

Re: Script problem again!

Post by metal_head »

jonas wrote:Don't you love that? :D You look at it over and over, then someone else looks at it once and sees it. Always makes me feel like a genius. :lol: Good thing we have our screens to hide behind. :mrgreen:
I'll have to totally agree with you, it happens to me just all the time :D
User avatar
GMer
Posts: 329
Joined: Thu Oct 25, 2007 4:49 pm
Location: On the rock in the 3rd solar orbit.

Re: Script problem again!

Post by GMer »

Y'know what they say: two heads are better than one :)
Well, I've solved some problems scripting by myself (yay!), but I am stuck on this one.

Code: Select all

{
   INCREASETIMER   [0]
   TIMERAMOUT      [0.5]
   SOUNDAMOUNT	   [1]
   SOUND	   ["sound"]
   SOUNDAMOUNT	   ["healthlow.wav"]
   THRESHOLD	   [30]
   VARIABLE	   [health]

   Spawn[ ()
   {
      Console(true);
      LowLevel("Keycheck");
   } ]

   Keycheck[ ()
   {
      if(INCREASETIMER < self.time)
      {
         if (GetAttribute(VARIABLE,"Player") > THRESHOLD)
         {
            ModifyAttribute(SOUND,0,"hc");
         }
         else
         {
            ModifyAttribute(SOUND,1,"hc");
         }
         INCREASETIMER = self.time + StringCopy(TIMERAMOUT);
      }
      debug(GetAttribute(SOUND,"hc"));
   } ]
}
For a placeholder for the sound I have an attribute (which works great), and the script does recognize the player's health, just the "SOUND" attribute won't change when the player gets below THRESHOLD. :?
I think I may have the "if (GetAttribute(VARIABLE,"Player") > THRESHOLD)" wrong...
Over 3 years (has it been that long?) and just now I noticed the day and month of my birthday were switched. Whoops!

Some 2d games I made, haven't made anything in a year though O.o
http://www.yoyogames.com/users/GMer56
User avatar
Juutis
Posts: 1511
Joined: Thu Jan 12, 2006 12:46 pm
Location: Finland

Re: Script problem again!

Post by Juutis »

So in the ModifyAttribute() command, are you trying to reference an attribute called "SOUND" or the variable SOUND (which contains the string "sound")?

Also, when initializing variables in the beginning, don't use the quotation marks for strings. Those quotation marks actually get included in the string so right now the script actually tries to modify an attribute called ""sound"". So get rid of them:
SOUND [sound]

And I find this kinda funny:

Code: Select all

INCREASETIMER = self.time + StringCopy(TIMERAMOUT);
Simkin can be a real pain in the ass when it comes to the types of variables. And TBH, this doesn't help at all. :) Turning a float into a string and then adding it to a float again is, well... not very clever. You're better off without the StringCopy() command there. ;)
Pain is only psychological.
User avatar
GMer
Posts: 329
Joined: Thu Oct 25, 2007 4:49 pm
Location: On the rock in the 3rd solar orbit.

Re: Script problem again!

Post by GMer »

Ok, so I need to:
A) remove the "StringCopy" command
B) remove the quotes on for the variable "sound" when defining it in the beginning (which is supposed to have a variable either 1-for on- and 2- for off)

Although it would probably just be easier to do the "PlaySound()" command instead of using the sound variable, a sound playing is a good enough diagnostic.
Over 3 years (has it been that long?) and just now I noticed the day and month of my birthday were switched. Whoops!

Some 2d games I made, haven't made anything in a year though O.o
http://www.yoyogames.com/users/GMer56
Post Reply