Problem using GiveScore from global function

Started by yort, Tue 25/10/2005 02:45:02

Previous topic - Next topic

yort

Hi,

I've only been using AGS for a week now, so I'm assuming my problem is caused by something I'm doing, and I'm hoping someone will be able to show me the error of my ways.
???

I am using AGS 2.70.601 on Windows XP SP2.

At the momentÃ,  I am calling the GiveScore function from a custom function in my global script, which is itself called from the interact script on several different objects in different rooms. This is because I want the same behaviour when the user clicks the same inventory item on different objects through out the game.

For the most part, the code seems to work, except that intermittently (and more often than not) the GiveScore function does not seem to update the players score. The sound effect associated with a score increase does play, but the two GUI's I have that show the score do not update. I should probably mention at this point that I am using a modified version of the SQ4 template (and so I'm using it's GUI's etc).

I have checked my script code and the GUI, as well as looked in the knowledge base and googled the problem but I haven't found any solutions, or indeed anyone else who seems to be having the same problem.

The really confusing thing about my problem is that the score does update sometimes, just not all the time.

I have placed code in the on_event function in the global script to explicitly update the score on one of the GUI's, but it hasn't helped.

Any ideas ?

Thanks in advance.

PS : Here's the code from my global function
function StandardDustInventoryUseScript()
{
Ã,  if (character[EGO].activeinv==3)
Ã,  {
Ã,  Ã,  GiveScore(1);
Ã,  Ã,  Display("&169 Congratulations, you've successfully cleaned up the dust.");
Ã,  }
Ã,  else
Ã,  {
Ã,  Ã,  StandardInventoryUseScript();
Ã,  }
}

function on_event(EventType event, int data) {
Ã,  
Ã,  string message;
   if (event == eEventGotScore)
Ã,  {
Ã,  Ã,  StrFormat(message, "Score : %d of %d", game.score, game.total_score);
      gGui5.Controls[0].AsLabel.SetText(message);Ã,  Ã,  
}


Gilbert

Hmmm is it possible that these "GiveScore" lines are sometimes executed when the game is blocked? (like during a blocking cutscene, while someone talking, etc.)
In that case it may be possible (I'm not sure) that the on_event() function won't get called during the process, and be called only after the blocking is completed.

I'll recommend try not to use the on_event function for such purpose, instead you can make a wrapper function like below:
function GiveScoreCustom(int value){
Ã,  string message;
Ã,  GiveScore(value);
Ã,  StrFormat(message, "Score : %d of %d", game.score, game.total_score);
Ã,  Ã, gGui5.Controls[0].AsLabel.SetText(message);Ã,  
}

And if your rooms need to call that also, put in the header:
import function GiveScoreCustom(int value);


Whenever you need to give score, use GiveScoreCustom() instead of the original GiveScore().

yort

Thanks for your suggestion. It sounded good, so I tried it, but it doesn't seem to have helped.   :(

As far as I know, I'm not calling the function during a cutscene or while someone is talking (although speech could occur before or after the function call I guess).

I tried changing the script on one of my objects so it used the interaction editor options instead of my script. The options were basically

1. Condition (if inventoryitem 3 used)
  2. Move charactger
  3. Remove object from room
  4. Add score (1)
  5. Display message
  6. Display message
  7. Display message
  8. Stop running more commands.

Interestingly enough, I get the same problem, *sometimes* the score updates and sometimes it doesn't.

It's confusing because the sound for the givescore function plays, but the gui's don't update.

The second gui I have that shows the score does so by putting @SCORE@ of @TOTALSCORE@ in the text property of a label. I ASSume this means the label will update itself automatically, or at least re-read the values when the GUI is shown, but in any case this GUI doesn't update either.

Is it possible there is a bug that means the score itself isn't being incremented, or is it really likely the guis just aren't updating ?

SSH

You coudl try and use the debug stuff of hitting the "`" key and seeing games events or using Scroll Lock and single-stepping through code with left-shift to see which lines of code are executed... this might throw some light on things.
12

yort

Excellent ideas. I'd already tried the debug window, but forgotten to post the details (sorry). Here's what it shows when the score doesn't update :

ego start move
ego face location
playing sound 1 on channel 3
object 1 turned off
object 1 stop moving

I tried the scroll lock thing (which I didn't know about - cool !), but it didn't seem to work. As soon as the character finished walking to the object, a global message was displayed. Pressing shift didn't seem to step passed the message, and as soon as I clicked to make it disappear the rest of the script seemed to run to completion immediately.

I tried swapping my code around so the GiveScore function is called AFTER the message is displayed, in case the game engine is blocking the events like Gilbot V7000a suggested, but this made no difference either.

Clues anyone ?

SMF spam blocked by CleanTalk