Scripting User input to certain animation (SOLVED)

Started by vjamesv, Sun 07/01/2007 22:50:03

Previous topic - Next topic

vjamesv

I have a GUI that opens and asks the used how fast they would like to drive a motorcycle up a ramp.  i have a text box that fits in two digits, and then an OK button that closes the gui.  i would like it so that when the number that has been input is between 0-9 that it will play an animation, and then 10-19 will play a different one, and so on.  i have played around with the script but cannot figure out how to get it so that when they hit ok it will play an animation.

right now i have the animation set up so that the motorcycle is a character, and i have a background that i have made a separate room with the ramp.

can someone please help me with this?  thank you. 

This is for my game Banana Man.  I have the backgrounds completed, as well all the animations.  The game is scripted about 3/4 of the way through, and beyond that i just have a few fun little things like the ramp script to throw in. 

Khris

You could use CallRoomScript just after you've made the GUI invisible.

Then add the on_call function to the ramp room's script and put in it what's supposed to happen after the click on OK.

Ashen

Since the Motorbike is a Character and not an Object, you could just call it from the Global Script (although you might have to gheck which room the player is currently in, if the GUI could be open anywhere else).

Also, use the TextBox.Text and String.AsInt functions to get the inputted value. Not that String.AsInt will return text input as 0 (e.g. if the player enteres 'XX' it'll count as 0), so you'll probably want to add an extra check to make sure 0 really is 0.
I know what you're thinking ... Don't think that.

vjamesv

Your responses have been helpful, but I cannot get this to work.  I have created a GUI that asks the user if he wants to use the motorcycle.  If the user clicks yes, another GUI pops up asking how fast. I have created the text box and an ok button.  Clicking OK makes the GUI disappear.  I have no idea how to manipulate the input though.  i have been trying to type different scripts into the function for the ok button, but i cannot get anything to compile when i do that.  Can someone please help me to just get started so that i can play an animation, any animation, when the user clicks the ok button.  Thank you in advance.

Khris

What code did you try? What error did you get?

(I can't believe I have to ask this over and over again.)

vjamesv


be nice

i am not at my computer at home with AGS, but i was asking if i am putting things in the right spot by placing the code in the script for the ok button.  when the user clicks ok, i have the gui disappear, and then I tried putting something like:

if (biketext.Text == 1) {
Display ("something")
}

which i realize i need to use AsInt somehow, but i don't know if i am doing in the right place to be able to play an animation depending on the input.

Ashen

Think about it logically - if you want the animation to play when the player clicks the OK button, then that's probably the best place for it. (Unless you want to use CallRoomScript and have te actual code in the room with the ramp.

And actually, that's not what you asked - you asked how to "play an animation, any animation, when the user clicks the ok button". Since that's answered fairly simpley in the manual, there must be something in your code that's stopping it from playing which is why you need to show what you've got, as well as any errors you might be getting. I'm a little surprised it needs to be said over and over as well.

I guess biketext is the TextBox you get the input from? So, biketext.Text is the String you want to get as an Int. Try:
Code: ags

int Speed = biketext.Text.AsInt; // So you don't have to type 'biketext.Text.AsInt' for every conditon
Display ("Speed = %d", Speed); // runs whatever value is entered
if (Speed == 1) 
  Display("Something"); // only if 1 was entered


You could directly check the String value of the input (if (biketext.Text == "1")) for every possible input, but that just seems like a lot of pointless work...
I know what you're thinking ... Don't think that.

vjamesv

#7
yeah, you be nice too!  but i have to say, ashen, your scripting is exceptionally nice!  It worked perfect!  I am busy right now finishing all the coding for the 10 different animations for this.  there are only two more scripting sections to go in my game, so hopefully i won't have too many more questions before i am finished, and hopefully you will have a great new game to play!

Actually, one last question on this, how do i check to make sure that a number is entered and not text?  i know you mentioned, and you are right: as of now, if letters are typed in, it is treated as a zero.

Ashen

We are nice, we just get grumpy when we have to repeat ourselves  ;D

You could add an extra check specifically for the String value of 0 (if(biketext.Text == "0") ... ) - I think that's the only way to tell an actual 0 from 'no numbers where entered, so call it 0'. What about:
Code: ags

int Speed = biketext.Text.AsInt; // So you don't have to type 'biketext.Text.AsInt' for every conditon
if (Speed == 0 && biketext.Text != "0") {
  // If the player enters a text value, clear the box and have them try again
  Display("Invalid value entered, try again.");
  biketext.Text = "";
}
else if (Speed >= 0 && Speed < 10) {
  // Speed is in range 0 - 9, run appropriate anim
}
else if (Speed >= 10 && Speed < 20) {
  // Speed is in range 10 - 19, run appropriate anim
}
  // Etc. for other ranges of Speed
}
I know what you're thinking ... Don't think that.

vjamesv

Worked perfect.  Thank you so much.  Hopefully this weekend i can start working on the last two scripts i have to do, and hopefully my questions won't make anyone grumpy!!!

Khris

As I've already mentioned in the other thread, it's not necessary to use ten else ifs.

Pseudo
Code: ags
if (invalid value was entered) {
  ..
}
else {
  int view=Speed/10+3;   // 0-9 -> 3; 10-19 -> 4; 20-29 -> 5; aso.
  play anim;
}


vjamesv

thanks for letting me know after i typed in all the code!  yeah, i know you put it in my other thread, i was trying everything and finally got it to work.  still, it is great to know how to clean up some of my code.  thanks again for all the help

Ashen

Ah, sorry, I didn't realise your views were that well organised. No, there's no need to have ten if ... else ifs if the views are like that, and if nothing else (e.g. anim speed) needs to change.
(Actually you could set up arrays to store the view numbers, speeds, etc, and still use Khris' condensed version anyway - but I think the else if structure LOOKS clearer for demonstraition purposes, even if it's not the best way to go here.)
I know what you're thinking ... Don't think that.

SMF spam blocked by CleanTalk