Menu

Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Show posts Menu

Messages - CatLover

#1
Quote from: RickJ on Sun 11/04/2010 04:33:56
You could use a custom function to talk with that particular NPC.  The function would increment a conversation counter each time it is executed.   The conversation counter would then be queried to determine which topic should be started.   The counter is implemented using a static variable which means that it is declared outside the bounds of any function.  The values of static variables are persisted through out the game.  Dynamic variables, those defined within the bounds of a function are only defined while the function is executing and it's values are not save from one execution of the function to the next.

Here is a code example illustrating the technique.  It's not complete or error free but should give you a good idea of how to do this.  Hope you find ithis helpful.
Code: ags

*** Room Script Example ***

// Define a conversation counter for this particular NPC
// and initialize it to zero
int SomeNpcConversationCounter = 0;

// Create a custom function used to talk with this particular NPC
function TalkToSomeNpc(Dialog *topic) {
   // If this is the first time talking to the NPC named "SomeNpc" 
   //  then use dTopic1 or whatever name you prefer.
   if (SomeNpcConversationCounter<=0) {
      StartDialog(dTopic1);
   }
   // If this is the second time talking to the NPC named "SomeNpc" 
   //  then use dTopic2 or whatever name you prefer
   else if (SomeNpcConversationCounter==1) {
      StartDialog(dTopic2);
   }
   // If you have talked with the NPC 3 or more times then use 
   // the topic passed in as the parameter. 
   else {
      StartDialog(topic);
   }
   // Add one to the conversation counter
   SomeNpcConversationCounter++;
}

// This is a function created using the Interaction editor (i.e. using the 
// llighting bolt icon in the lower right hand pane of the editor).  It is executed
// in response to some player action such as a mouse click on an NPC or other
// game entity.
function room_SomeInteraction() {

   // Talk to the NPC named SomeNpc.
   // The first two times the dTopic1 and dTopic2
   // will be started.  On subsequent times dTopic3
   // will be started.
   TalkToSomeNpc(dTopic3);
}


PS: Catlover I have 6 cats, all rescued, all all ornry as hell!  ;)


Thanks RickJ, I was using a dynamic variable, not a static variable :)

I only have one cat, bought, and desexed :(
#2
I want to make it that you have one conversation with an npc the first time you talk to them, and you then exit the conversation and no options come up. All the other times you talk to the npc, it has a different conversation, which then again quits immediately with no options. Any ideas on how I should go about this? ???
#3
Quote from: Ryan Timothy on Sun 11/04/2010 03:04:12
It's supposed to be run within a function, not as a function or outside of a function.

If this Miner was to animate from the moment you enter that background, you add it to the After Fade In function, like so:
Code: ags
function room_AfterFadeIn()
{
   cMiner.Animate(5, 5, eRepeat, eNoBlock);
}

Note: this must be created from within the room editor, or else it won't work -- Unless you've already done so.

How to create the After Fade In function:
In the room editor, on the bottom of the project tree, click on the lighting bolt and you'll see "Enters Room after fade-in".  Click on the dots beside it and it will be created in the room script (exactly like above without the character.animate).



If you were to actually create a function and call it at a certain point, you do this (outside all other functions):
Code: ags

function AnimateMiner()
{
  cMiner.Animate(5, 5, eRepeat, eNoBlock); 
}

You really wouldn't want to create a function for a single action such as this.  I'm showing you since you didn't seem to know how a function worked.

Then when you need to use it within your scripts, you just simply call:
Code: ags

AnimateMiner();


But make sure this doesn't get thrown into the repeatedly execute script without some kind of boolean check to prevent it from being called over and over.

Thanks a lot Ryan Timothy!!!
#4
I am trying to make an npc animate constantly, using Character.Animate in the room script, but its not working.

First, I tried this:
function cMiner.Animate(5, 5, eRepeat, eNoBlock);
but it said "Variable cMiner already imported"

Next I tried it without "function":
cMiner.Animate(5, 5, eRepeat, eNoBlock);
but that created a parse error "Unexpected cMiner"

What should I do? ??? 

P.S. I am new to AGS and this is my first post, so I've probably done soething really stupid.
SMF spam blocked by CleanTalk