I will try and explain it as simply as I can. I have probably used too many words.

Lets say I have a program called Program1.c . In this program, I have a main function.

Now lets say I can a second program called Program2.c . On the top of Program1.c , I have this code:

#include "Program2.c"

I have #included Program2.c to be used by Program1.c , because Program2.c has functions in it that need to be called on by Program1.c in order to initiate certain actions.

Lets say that there is a function inside Program2.c called print_text() that accepts a string to a variable called "string_output": print_text(String string_output) . Suppose that this variable "string_output" is not declared as a variable in Program1.c , even though Program1.c needs to access this value from Program2.c .

Lets also say that Program1.c passes strings as needed to print_text() (which is stored in Program2.c) in order to output text on the screen. So if Program1.c passes the string "strawberry" to print_text():

Example:
Code:
print_text("strawberry");



...then the word "strawberry" will be displayed on the screen.

Now lets go a step further. Suppose that Program1.c wants to be able to attach a sword (.mdl sword model) to the player's hand to wield as a weapon, only if Program1.c passes the string "sword" to print_text(). Example:

print_text("sword");

In order to accomplish this, Program1.c holds a function called string_compare() that tries to compare the value of the string variable "string_output" currently saved in the print_text() function stored in Program2.c , to the string "sword". If the string value of string_output equals "sword", then a .mdl sword model will be attached to the player's hand. If they are not equal, then the .mdl sword model will not be attached to the player's hand:

Example:
Code:
// Stored in Program1.c

function string_compare()
{
   if(str_cmp(string_output, "sword")) // string_output is stored in 
                                       //    print_text() in Program2.c .
                                       //    How can Program1.c access the
                                       //    string_output string value in
                                       //    print_text() function, Program2.c ?
   {
      ent_create ("sword.mdl", my.x, attach_weapon); // Attaches a .mdl sword
                                                     //    to player's hand.
   }
}



How can Program1.c access the string value of "string_output" stored in Program2.c? As of now, I have this logic in my program, but I am getting an error on string_output variable in the string_compare function inside of Program1.c .

Last edited by Ruben; 12/28/13 07:25.