Custom Function Not Working [SOLVED]

Started by SpastikChuwawa, Thu 09/07/2009 17:36:46

Previous topic - Next topic

SpastikChuwawa

 I've run into yet another snag. I made a function that doesn't seem to be working.

In the game, the character has to collect three items. When he collects each one, 1 point is added to the Materials global variable (Materials ++,). When he collects all three, I want a Display to show up telling him he collected all the items and whatnot.

Here's my function code:

function All_Materials(EventType event, int data){
if(Materials==3){
 Display("You found all the materials!");
}
}

At the bottom of Global Script.asc I placed:

export All_Materials;

Then in the Script Header in Global Script.ash, I put:

import function All_Materials(EventType event, int data);

But when I play the game and get all the necessary items, the function doesn't pop up at all. I made sure all the items have a Material++ at the end of their Interaction functions, yet it still won't work. Any help would be mucho appreciated.

GuyAwesome

Is that all there is to the function? What do those parameters do? (It looks like you just copied and edited the on_event function declaration.) Can you give an example of what you're doing when the items are collected? The code's pretty basic, but it should work OK, if Materials ever reaches 3... Throw in a Display("%d", Materials); - outside the condition - to check what's happening with it. If it's never 3 or never displays anything at all, the problem probably isn't with the function but where you're using it.

If that's all you want to do, the function is perhaps a little overkill. You could just add if(Materials==3) Display("You found all the materials!"); at the end of each of the interactions. Or, move the Materials ++; line into the function.

Khris

Custom functions are never run automatically, you have to call them yourself.
And you don't need to export functions.

Code: ags
//header

import All_Materials();

// global script

function All_Materials() {
  if(Materials==3) {
    Display("You found all the materials!");
  }
}


Then, when picking up one of the three:

Code: ags
  Materials++;
  All_Materials();

SpastikChuwawa

 Thanks guys! That seems to have done the trick, Khris.

SMF spam blocked by CleanTalk