Possible Bug? (SetGameSpeed)

Started by Kurdt, Mon 10/07/2006 20:39:38

Previous topic - Next topic

Kurdt

Okay, so I've read the manual, sifted through tutorials, asked my friends, and done searches on this site regarding my problem, so now I'm posting. I'm trying to get a slider that controls my speed on my control panel GUI, and I've written script like this:

#sectionstart SliderSpeed_Change//SPEED SLIDER
function SliderSpeed_Change(GUIControl *control, MouseButton button)
{SetGameSpeed(SliderSpeed.Value);}
#sectionend SliderSpeed_Change//SPEED SLIDER

Where SliderSpeed is the name of my slider. According to my understanding of the manual, this is how you do it. However, when I attempt to use the slider ingame, I crash and it throws up this error:

Error: run_text_script1: error -1 running function 'SliderSpeed_Change':
Runtime error: wrong number of parameters to exported function 'SliderSpeed_Change' (expected 2, supplied 1)

Is this a bug in AGS or is there something I'm missing in my n00bness?

It should also be known that when I use SetGameSpeed elsewhere (like in game_start) and supply it with an actual number (in this case 60), it works exactly like it should. What am I doing wrong here?
"The reason why so few good books are written is that so few people who can write know anything."

Khris

I've created a slider, then named it "SliderSpeed", too.
After double-clicking it, I ended up with this:

Code: ags
#sectionstart SliderSpeed_ChangeÃ,  // DO NOT EDIT OR REMOVE THIS LINE
function SliderSpeed_Change(GUIControl *control) {
Ã,  
}
#sectionend SliderSpeed_ChangeÃ,  // DO NOT EDIT OR REMOVE THIS LINE


Just remove the MouseButton parameter, then it should work fine.

I've no idea how you ended up with the wrong number of parameters.
Did you manually write the "#section"-lines?

Kurdt

That took care of it. Thanks!

I've no idea how it happened, either. I manually wrote the #section lines for my volume slider and then copied & pasted it for the speed slider, changing the commands and file names of course. I don't see how something like that could throw up a wrong number of parameters, though.
"The reason why so few good books are written is that so few people who can write know anything."

Khris

Well, you don't have to write those lines manually, or better: you mustn't.
AGS automatically creates them. Just name the GUIControl, then double-click it.

The # lines are in the scripts only for AGS to know where the functions for the different elements are located.
E.g. deleting a GUIControl will automatically remove everything from the related #sectionstart to #sectionend, so it's really a bad idea to create them manually, since that could (and probably will) mess up AGS's automatic handling of the script.

Kurdt

...interesting. When I double-click it, does it automatically appear in the script before me or is it hidden from my view?
"The reason why so few good books are written is that so few people who can write know anything."

Khris

Like I said, after naming the Control, double-click it.
A little window pops up where you can rename the function, if you want. ("[Script name]_Change" is the default for sliders).
Click "OK", and the global script editor will open, with the cursor positioned conveniently at the newly created function's first line.

Kurdt

#6
Oh, I see what you mean. I do that all the time, but the script never pops up with the #section already written in. If I want it to do anything, I have to go in and make it manually.

EDIT: Nevermind. There was a misunderstanding as to what I was supposed to double-click on. Thanks for the shortcut!
"The reason why so few good books are written is that so few people who can write know anything."

SMF spam blocked by CleanTalk