Is it possible to specify the duration of background frames?

Started by orient, Sat 02/10/2010 09:25:57

Previous topic - Next topic

orient

...or is that functionality limited to objects only?

I want to create a "flickering light" effect between 2 images:
Light off


Light on


I basically want the light to flicker on and stay on for a good 15 seconds or so, with some flicker in between, then turn off for a few seconds, and repeat. I initially attempted to get this working using Visible and Wait commands but failed, so any help would be greatly appreciated :-)

Cheers.

GarageGothic

I can't really tell if there's an overall lighting difference between the backgrounds or it's just the light above the door. If the latter, you could simply use an animated object for the door area. If it's the whole background, you just have to import a secondary background frame (click the "Background to display" drop down menu in the room editor and choose "Import new background"), then use the BackgroundAnimationDelay property under "Settings" to specify the timing.

orient

Yeah it's just the light above the door.

The problem with using animated backgrounds is, I want the background to change at different speeds, so flick between the 2 images really quickly then stop, then slowly, quickly etc. and I don't think that's possible, is it?

If not, and I have to do it with a object, how would I go about swapping between two frames using such irregular timing?

GarageGothic

Well, it is possible with background animation, but you'd have to do it manually (i.e. set up a timer, check for when it runs out in rep_exec(), switch background frames, set a new timer, repeat). With objects you can set the delay for each individual frames in the View editor.

orient

Ah ok, cool. I've created the view (vFlicker) consisting of the 2 frames (although I will add more) but I've forgotten how to assign the view to the object on-screen?

GarageGothic

Object.SetView(int view, optional int loop, optional int frame)

orient

Sorry -- I've got it to work but the animation doesn't seem to be looping between the two frames. It's just sticking on the first one, and I haven't changed any delays or anything.

GarageGothic

Object.Animate(int loop, int delay, optional RepeatStyle, optional BlockingStyle, optional Direction)

:)

orient

Invalid loop number specified  >:(

*Edit* Don't worry, got it working. Thanks very much for your help, and putting up with my n00b issues :D

GarageGothic

What loop number did you put? The first loop in a View is 0.

orient

Yeah I just remembered that, cheers.

I've got another small question to ask if that's alright -- Is there a way to fade between two frames of animation? For example, frame 1 in the view fades from 100 to 0 opacity as frame 2 does the opposite? Or would that effect need to be done manually in an image editor?

GarageGothic

There's no built-in function to do that, but you could use the Tween module to fade one object out and another in for a similar effect (if either frame is identical to the background it covers, you'd just need a single object).

orient

Ah sweet. I'll give the module a try, thanks. My hope is to create a dust particle effect in the air. Don't be surprised if I resurrect this thread from time to time if I can't find answers using the search feature :P

orient

I have a few more questions...How do you change a character's dialogue the second time you click on them? So the first time this happens:

Code: ags
function cMystMan_AnyClick()
{
  cMystMan.SayAt(20, 360, 600, "Blah Blah Blah.");
}


What if I want him to say something different the second time?

Also -- I'm fairly sure this can't be done -- but can you have multiple colours within a text string? For example, have, "Character Name:" in red, followed by his speech in blue? Or maybe have two strings appear at the same time, one red (above the speech) and one blue?

Thanks for your help.

GarageGothic

For the first question, you can use Game.DoOnceOnly(const string token):

Code: ags
function cMystMan_AnyClick() {
  if (Game.DoOnceOnly("TalkedMystMan") cMystMan.SayAt(20, 360, 600, "Blah Blah Blah.");
  else cMystMan.SayAt(20, 360, 600, "I already told you: Blah!");
  }


Or, if you want to use it throughout the game and possibly have more than two replies, you could check out the MultiResponse module.

For the colored text, it would probably be easiest to write a custom Say function that displays a GUI with two labels - one with red text, displaying the name of the speaking character, and one blue displaying the spoken String. Putting the name above the spoken line is less trouble than displaying it in front of the text with the dialog linebreaking around it, but that's possible too (could be done either with DrawingSurface functions, or stick to the above, but add a number of blank spaces equivalent to the width of the character name to the beginning of the dialog String).

orient

Awesome. I read about the module and bookmarked it for later. For the time being I'll try and make as much as possible without the more complex scripting. Any puzzles in the game shouldn't be too complex.

orient

I'm having a bit of trouble with the Game.DoOnceOnly method. I straight-up pasted your code into my game and it came up with this error: "end of input reached in middle of expression"

I thought it could be a simple syntax error so I tried to change the code myself to what I thought might work:
Code: ags
function cMystMan_AnyClick() {
  if (Game.DoOnceOnly("TalkedMystMan") {
    cMystMan.SayAt(20, 360, 600, "Blah Blah Blah.");
  else cMystMan.SayAt(20, 360, 600, "I already told you: Blah!");
  }
}

...but I failed :-P Same error again.

I couldn't get that working, so I decided to install the MultiResponse module, which works great. However, I've been using SayAt because I want all dialogue to appear down the bottom of the screen, but I can't find a way to specify the x, y & width with MultiResponse (I'm using .MultiSay). So I'm kind of at a stand-still with dialogue at the moment.

GarageGothic

Sorry, my bad - I forgot a closing parenthesis on the if-line:

Code: ags
function cMystMan_AnyClick() {
  if (Game.DoOnceOnly("TalkedMystMan")) cMystMan.SayAt(20, 360, 600, "Blah Blah Blah.");
  else cMystMan.SayAt(20, 360, 600, "I already told you: Blah!");
  }


Edit: As for the MultiResponse module, I have zero experience with it. You'd be better off posting questions in the module's own thread.

orient

Cool. I'm just trying to figure out how to have a "conversation" using this DoOnceOnly. I got this much working:

Code: ags
function cMystMan_AnyClick() {
  if (Game.DoOnceOnly("TalkedMystMan")) cMystMan.SayAt(20, 360, 600, "That's far enough. The car's open. Put the cash inside and we'll count it.")
  && cEgo.SayAt(20, 360, 600, "Half now, half after -- right?");
  else cMystMan.SayAt(20, 360, 600, "The money in the car, then we'll talk.");
}


But I really need more back and forth between the characters and adding another && doesn't work. Do you know of a way to add multiple strings like this?

GarageGothic

#19
This code, along with the "fixed" script you posted before (where you had put the "else" part inside the brackets) make me think you should re-read the scripting tutorials in the manual. Get a good understanding of brackets, "if" statements and the use of conditional symbols like && and || before going into proper scripting - it'll save you a bunch of troubleshooting.

Edit: Sorry, didn't realize what you were trying to do - I thought you meant a third response. Now I see what you want, and for that you need an extra set of brackets after the if-statement:

Code: ags
function cMystMan_AnyClick() {
  if (Game.DoOnceOnly("TalkedMystMan")) {
    cMystMan.SayAt(20, 360, 600, "That's far enough. The car's open. Put the cash inside and we'll count it.");
    cEgo.SayAt(20, 360, 600, "Half now, half after -- right?");
  }
  else cMystMan.SayAt(20, 360, 600, "The money in the car, then we'll talk.");
}




Below is the first code I had written, based on my erroneous impression of what you were trying to do.
Just keeping it in case you need a reference for multiple replies.
******************************************************************************
To add another response, just use Game.DoOnceOnly again with a new identifier String. Like so:

Code: ags
function cMystMan_AnyClick() {
  if (Game.DoOnceOnly("TalkedMystMan")) cMystMan.SayAt(20, 360, 600, "That's far enough. The car's open. Put the cash inside and we'll count it.");
  else if (Game.DoOnceOnly("TalkedMystManAgain")) cEgo.SayAt(20, 360, 600, "Half now, half after -- right?");
  else cMystMan.SayAt(20, 360, 600, "The money in the car, then we'll talk.");
}

SMF spam blocked by CleanTalk