Frictional Games Forum (read-only)
how do I use global variables concept? [Solved] - Printable Version

+- Frictional Games Forum (read-only) (https://www.frictionalgames.com/forum)
+-- Forum: Amnesia: The Dark Descent (https://www.frictionalgames.com/forum/forum-6.html)
+--- Forum: Custom Stories, TCs & Mods - Development (https://www.frictionalgames.com/forum/forum-38.html)
+---- Forum: Development Support (https://www.frictionalgames.com/forum/forum-39.html)
+---- Thread: how do I use global variables concept? [Solved] (/thread-11670.html)



how do I use global variables concept? [Solved] - jssjr90 - 12-04-2011

Im realy stuck in this concept of Global Variables. This is what I want to get done in my map, I know how to do the functions and stuff, its just I need to let the last function only happen if the player did this function and this one, ect. in a global stance, becouse the functions will happen though multiple maps. Heres the lay out of the draft of tasks. So in essence, only activate the last function IF the player did all the other functions. And the tasks are though out multiple levels.


1.Talk to "Martin Smith" - Henry's freind over the phone about his loss and other things.
2.Get the "letter" and combine it with the "pen father" = singed letter
2a Get "singed letter" and combine it with envelope = envelope with the bill.

3.Mail the letter in the mail box in the front yard.
4.You observe other places around the house. Such as the pile of wood that is blocking a path to a secret crypt, and the basement door that is locked from the inside that is on the side of the house.
5.You observe the fireplace that you feel a faint draft comming from down below.
6.Go upstairs to oberve a wall that has a strange feel to it. (Antic room is sealed off with bricks.)
7.With in upstairs, oberve the ceiling, the atic door is ontop of the ceiling. ceild off as well.
8.Read Johnathen's Note
9.Go to the shed, but its locked. (the shed has rope to use to get in the attic.)
10.The shed key is hidden in between the vases by the stair case.
11.You can only get the key by opening the curtens to see the key.
12.Go back to the shed to get the rope.
13.Apply the rope to get into the atic's window.
14.Read John Marley's direy about his stay in the manor.
15.There is a cabonet in the attic, behind that cabonet is a secret room.
16.You observe a loose floor boared.
17.You will also find one small dose of oil for the lantern.
18.You find a small box that you will put on your desk in your room. The box is locked.
19.Go back down stairs 1F to talk to "Martin Smith" about your findings of the atic and the direy you found.
20.You find your self tired from the day and can go to bed. [IF the player did everything in the list, then activate this function of going to bed.]


RE: how do I use global variables concept? - Acies - 12-04-2011

This should probably be placed in developement support. Secondly I'm not the best scripter :>

I would do it like this:

To each of the events you described insert a;

AddGlobalVarInt("TasksDone", 1);

The value starts at 0, so for each "task" done it adds one to it. After all of the 20(?) tasks are done; the variable "TasksDone" should be = 20.

Then at the end (going to bed):

void ToBedFunc()
{
if (GetLocalVarInt("TasksDone") == 20)

{
FadeOut(4);
//And so forth
}
else
SetMessage("Tips", "AllTasksAreNotDone", 0.0f);

}




RE: how do I use global variables concept? - jssjr90 - 12-04-2011

So how do I set each function to add a 1 to the tasksdone variable? and check it and stuff. Can you please explain more in detail, im just so new to this global variables stuff.


RE: how do I use global variables concept? - Acies - 12-04-2011

As you can hear by the name, this function adds one to the variable:
AddGlobalVarInt("TasksDone", 1);

You should insert it into the function for each event. For example: "1.Talk to "Martin Smith" - Henry's freind over the phone about his loss and other things."

I'm just speculating now, but let's assume it is triggered by clicking a telephone. Clicking the phone will play a sound/conversation between the main character and Martin. In the same function which plays the sound/executes the "happenings" simply insert the:
AddGlobalVarInt("TasksDone", 1);

That will add "1" to the variable "TasksDone". Just remember to insert it into do-once functions. By that I'm meaning you should not have it in a function which may be executed several times. Otherwise the player may do the same action 20 times (thus bypassing the demand for completing all of the tasks).

As for "checking" let's assume a second scenario; As the player enters a scriptarea close to the bed he will lie down and sleep if all of the 20 tasks are complete.

Here is the "checking part":
Spoiler below!

void ToBedFunc()
{
if (GetLocalVarInt("TasksDone") == 20)

{
FadeOut(4);
//And so forth
}
else
SetMessage("Tips", "AllTasksAreNotDone", 0.0f);
}




The line which says:
if (GetLocalVarInt("TasksDone") == 20)

Checks if "TasksDone" is equal to 20. If it is equal to 20 the player will "rest". Thus when all tasks are completed the variable "TasksDone" should be equal to 20; causing the player to sleep.

The "else" part in it says that if TasksDone is not equal to 20 it will instead display a message (which you could set to something like "I can't rest until I have finished todays jobs/tasks").


RE: how do I use global variables concept? - jssjr90 - 12-05-2011

I think im getting it, so I think I would set it up like this mabye

void OnStart()
{
SetEntityPlayerInteractCallback("phonecall", "phonecallfunc", true);

}



void phonecallfunc(string &in asEntity)
{
//"TasksDone" can be what ever i want like "TasksDoneLevel1"
AddGlobalVarInt("TasksDone", 1);

SetPlayerActive(false);
StartPlayerLookAt("phone", 0.2, 1, "");
AddTimer("", 1.0f, "stoplookat");
}
void stoplookat(string &in asTimer)
SetPlayerActive(true);
{
StopPlayerLookAt();
}



//Another map file where the bed is

void OnStart()
{
SetEntityPlayerInteractCallback("bed", "bedfunc", true);

}

void bedfuncfunc(string &in asEntity)

{
if (GetLocalVarInt("TasksDone") == 20)



{
//I know what to put. to change level incert here
}
else
SetMessage("Tips", "I was not tired yet", 0.0f);


}




So where do I set the Global main Variable so that it reads though all maps? Is it in some special file?





RE: how do I use global variables concept? - Acies - 12-05-2011

Skimming through it that seems about right. Nope, both global and local variables are "created upon use". As soon as you Add a value to "TasksDone" the variable is created and stored.


RE: how do I use global variables concept? - jssjr90 - 12-05-2011

Created upon use? So uhh im starting to get it but some things i dont get, like that created upon use thing. and is there some other place you supposed to put the main global variable that you declare other maps read it? becouse it would not make seance to put it in the normal map script file.
and also how would you structure that pic of code to make it work.


RE: how do I use global variables concept? [Solved] - jssjr90 - 12-29-2011

LOL! I mixed up GetGlobalVarFloat with GetLocalVarFloat, Match match match them! Dont mix your "IF" functions with these 2, pick one or the other! Match! LOL I feel so stupid!