Function to be called in "OnMouseClick" :
function gradual_solidity(int max_transparency, int speed, int type, int id){
Ã, int tran = 100;
Ã, int newtran = 100;
if (speed <= 100){
Ã, Ã, while(newtran > max_transparency){Ã, Ã, Ã, Ã,Â
newtran = tran - 1;
Ã, Ã, Ã, Wait(1);
Ã, Ã, Ã, if (type == 0){ //if it's for a character
Ã, Ã, Ã, Ã, SetCharacterTransparency(id, tran);
Ã, Ã, Ã, Ã, }
Ã, Ã, Ã, else if (type == 1){ //if it's for a GUI
Ã, Ã, Ã, Ã, SetGUITransparency(id, tran);
Ã, Ã, Ã, Ã, }
Ã, Ã, Ã, }
Ã, Ã, }
Ã, }
At run-time:
Error: run_text_script1: error -6 (Error (line 80): Script appears to be hung (150001 while loop iterations without an update)) running function 'on_mouse_click'
I see an update.Ã, But, I'm obviously doing something wrong.
Thanks for the help.Ã, :D
Your problem is that you are doing this:
newtran = tran - 1;
but tran is always 100, so newtran is always 99. Thus, the loop carries on forever.
I'm not sure why you have declared two different variables - this should work instead:
function gradual_solidity(int max_transparency, int speed, int type, int id){
int tran = 100;
if (speed <= 100){
while(tran > max_transparency){
tran = tran - 1;
Wait(1);
if (type == 0){ //if it's for a character
SetCharacterTransparency(id, tran);
}
else if (type == 1){ //if it's for a GUI
SetGUITransparency(id, tran);
}
}
}
}
ThanksÃ, :)
But I have yet another function-related problem.Ã, I am trying to make it so that the function scrolls in from the top of the screen.Ã, Here is the code:
function GUIScroll(int gui){
Ã, Ã, int tehx = mouse.x;
Ã, Ã, int tehy = -10;
Ã, Ã, int tehmousey = mouse.y
Ã, Ã, SetGUIPosition(gui, 150, -10);
Ã, Ã, if (mousey >= 270){
Ã, Ã, while (tehy < tehx){
Ã, Ã, Ã, tehy = tehy + 1;
Ã, Ã, Ã, SetGUIPosition(gui, tehx, tehy);
Ã, Ã, Ã, }
Ã, Ã, SetGUIPosition(gui, tehx, tehmousey);
Ã, Ã, }
Ã, }
Again, thanks in advance for the help.
What problem are you having with it?
The only obvious thing I can see is that there's no Wait call inside the loop, so it will slide into position immediately.
I got it to work using this:
function GUIScroll(int gui){
Ã, Ã, int tehx = mouse.x;
Ã, Ã, int tehy = -10;
Ã, Ã, int tehmousey = mouse.y;
Ã, Ã, SetGUIPosition(gui, tehx, 0);
Ã, Ã, GUIOn(3);
Ã, Ã, if (tehmousey <= 500){
Ã, Ã, while (tehy <= tehx){
Ã, Ã, Ã, tehy = tehy + 10;
Ã, Ã, Ã, SetGUIPosition(gui, tehx, tehy);
Ã, Ã, Ã, Wait(1);
Ã, Ã, Ã, if (tehx > 200){
Ã, Ã, SetGUIPosition(gui, tehx, tehmousey);
Ã, Ã, }
Ã, Ã, }
Ã, }
But I'm having an odd problem with it:
I want it to stop at the mouse.y and mouse.x position.
Ã,Â
If the function is called while the mouse is at the left-hand side of the screen (say, x < 53), everything works fine, and the GUI stops scrolling at the mouse position.
But, if the mouse is in the middle of the screen (between x > 54 and x < 199 or so), the GUI scrolls all the way to the bottom, then appears at the mouse position.
But the weirdest one is if the mouse is at the right side of the screen (x >=200 or something).Ã, The GUI scrolls to the very bottom ofÃ, the screen, then the game shows an error message:
Ã, ---------------------------
Adventure Game Studio
---------------------------
An error has occured. Please contact the game author for support, as this
is likely to be a scripting error and not a bug in AGS.
(ACI version 2.61.728)
(Global script line 100)
Error: SetGUIPosition: co-ordinates must lie in range (0,0) - (RMWID,RMHIT)
---------------------------
OKÃ, Ã,Â
---------------------------
It seems that the farther away from the left-hand side of the screen the function is called, the farther the GUI is scrolled, until it goes too far.
Thanks for (more :P) help.
:)
I think the error is in the while condition. You are testing (tehy <= tehx), but what you want to know is that (tehy <= tehmousey). You can see how this would cause the problems you describe.
What are the if-statements for? (tehmousey <= 500) should always be true (if you're running 320x200 rez). (tehx > 200) is just... irrelevant. These if-statements contribute to the strange behavior of your code.
There's also a minor bug where it might overshoot by up to 9 pixels and then snap back. (Hint: it's safest to update the variables tested in the while condition as the last thing you do in the loop. Otherwise the condition might not hold true throughout the loop.)
Here's a fixed version:
function GUIScroll(int gui){
Ã, Ã, int tehx = mouse.x;
Ã, Ã, int tehy = -10;
Ã, Ã, int tehmousey = mouse.y;
Ã, Ã, SetGUIPosition(gui, tehx, 0);
Ã, Ã, GUIOn(3);
Ã, Ã, while (tehy < tehmousey){
Ã, Ã, Ã, SetGUIPosition(gui, tehx, tehy);
Ã, Ã, Ã, Wait(1);
Ã, Ã, Ã, tehy = tehy + 10;
Ã, Ã, }
Ã, Ã, SetGUIPosition(gui, tehx, tehmousey);
}
Edit: Removed excess closing brackets
Yippee.Ã, It works...Ã, :)
But I decided to switch a few tiny things around to fit a tiny little unrelated bug that I just found.
In the end, I fixed it myself. It turned out that I had checked the wrong box for screen resolution (I feel so foolish :-[ ). So I fixed it around to fit that screw-up.
Thanks for the help, though!Ã, :)
We won't delete any related threads normally so I changed the [Delete me!] part to [Solved] as a common practice.