Facebook Twitter YouTube Frictional Games | Forum | Privacy Policy | Dev Blog | Dev Wiki | Support | Gametee


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Confused with void Func_Name
DaAinGame Offline
Member

Posts: 90
Threads: 11
Joined: Mar 2012
Reputation: 4
#1
Confused with void Func_Name

Being new to the scripting language I really want to learn but am having a extremely hard time grasping one part of the new language. I searched the forums and didn't come up with a thread relating directly to this but if there is one i apologize for posting this. Otherwise:
Basically, I cannot tell what comes after void. For example, I know that it is void Func_name() but i do not know what to put in the (). What I'm currently trying to do is make a Grunt poof after a timer of 45 seconds expires. Here's the script.
void OnStart()
{
AddUseItemCallback("", "key_1", "castle_1", "UsedKeyOnDoor", true);
AddUseItemCallback("", "key_2", "castle_7", "UsedKeyOnDoor1", true);
AddUseItemCallback("", "key_3", "castle_2", "UsedKeyOnDoor2", true);

SetEntityPlayerInteractCallback("key_2", "spawn_func", true);

}

void spawn_func(string &in item)
{
SetEntityActive("servant_grunt_1", true);
AddEnemyPatrolNode("servant_grunt_1", "PathNodeArea_1", 2, "");
AddEnemyPatrolNode("servant_grunt_1", "PathNodeArea_2", 0, "");
AddEnemyPatrolNode("servant_grunt_1", "PathNodeArea_3", 0, "");
AddEnemyPatrolNode("servant_grunt_1", "PathNodeArea_4", 0, "");
AddEnemyPatrolNode("servant_grunt_1", "PathNodeArea_5", 0, "");
AddEnemyPatrolNode("servant_grunt_1", "PathNodeArea_6", 0, "");
AddEnemyPatrolNode("servant_grunt_1", "PathNodeArea_7", 0, "");
AddEnemyPatrolNode("servant_grunt_1", "PathNodeArea_8", 0, "");
AddEnemyPatrolNode("servant_grunt_1", "PathNodeArea_9", 0, "");
AddEnemyPatrolNode("servant_grunt_1", "PathNodeArea_10", 4, "");
AddTimer("Fade", 45, "Fade");
}

void Fade (WHAT GOES HERE?)
{
FadeEnemyToSmoke(servant_grunt_1, true);
}

So far, I've managed to make it where I'm at through other guides, but even so I still don't understand how i can tell what goes in the (). (I also don't know if i scripted the timer correctly so can someone please check that for me?)

Also, as helpful as people are, I'd rather not have to rely on people every time I run into this problem. If somebody can give me a link or a good explanation on how to learn what to put there, I would appreciate it. Sorry if i seem uberly nooby at this, it's just that this coding language is just so different from what I learned. (LUA)

Realm Of Another Chapter 1: http://www.frictionalgames.com/forum/thread-14142.html
Realm Of Another Chapter 2: Postponed
Adder Halls: 5%
(This post was last modified: 03-11-2012, 08:01 PM by DaAinGame.)
03-10-2012, 02:32 AM
Find
Your Computer Offline
SCAN ME!

Posts: 3,456
Threads: 32
Joined: Jul 2011
Reputation: 235
#2
RE: Confused with void Func_Name

The script functions article provides the syntax required for each callback. If you know Lua, then you shouldn't have any trouble understanding this.

Tutorials: From Noob to Pro
03-10-2012, 02:50 AM
Website Find
Adrianis Offline
Senior Member

Posts: 620
Threads: 6
Joined: Feb 2012
Reputation: 27
#3
RE: Confused with void Func_Name

What goes in the condition for the function (i.e. the bit that goes in '()' after the function name) changes for which function CALLED that function in the first place.

To explain, you used the AddTimer function, which adds a function 'callback'. The specific conditions for the callback function when created by the AddTimer function are (string &in asTimer)

void AddTimer(string& asName, float afTime, string& asFunction);

Creates a timer which calls a function when it expires.
Callback syntax: void MyFunc(string &in asTimer)

asName - the name of the timer
afTime - time in seconds
asFunction - the function to call

The part you need to look at is the 'Callback syntax'. Now look at the function you used earlier,

SetEntityPlayerInteractCallback("key_2", "spawn_func", true);

void spawn_func(string &in item)

The correct 'Callback sytax' for this function is (string &in asEntity)

void SetEntityPlayerInteractCallback(string& asName, string& asCallback, bool abRemoveOnInteraction);

Calls a function when the player interacts with a certain entity.
Callback syntax: void MyFunc(string &in asEntity)

asName - internal name
asCallback - function to call
abRemoveOnInteraction - determines whether the callback should be removed when the player interacts with the entity

All this I've taken from the Engine Scripts page on the wiki,
http://wiki.frictionalgames.com/hpl2/amn..._functions

Hope this helps mate
(This post was last modified: 03-10-2012, 02:54 AM by Adrianis.)
03-10-2012, 02:52 AM
Find
DaAinGame Offline
Member

Posts: 90
Threads: 11
Joined: Mar 2012
Reputation: 4
#4
RE: Confused with void Func_Name

Adrianis, I can't tell if your post helped me or confused me even more. I understand the SetEntityPlayerIneractCallback and why the all the things in the () exist. But what really confused me on yours is when you talk about the addTimer function. What I understood from that is the void Func_name it goes under, nothing NEEDS to be added to the () for it to work. However, the function it calls (In this case the time after the grunt spawns to when it despawns otherwise 45 seconds) it should be like this?

void Fade(string &in asTimer)
{
FadeEnemyToSmoke("servant_grunt_1", true);
}

I do not feel as if this is right however?

**EDIT** Here's a good example of where I get really confused with the functions.
void LookRocks(string &in asParent, string &in asChild, int alState)
All i get from this is:
string &in asParent - going to be a string, so it will use a "". No clue about the asParent part.
string &in asChild - again, string, will use "", No clue about asChild.
int alState - int I'm guessing is an integer? alState is another ?. So I guess what my question truly is, is how do I figure out what does the second part means? I honestly feel totally lost and like a stupid head lol.

Realm Of Another Chapter 1: http://www.frictionalgames.com/forum/thread-14142.html
Realm Of Another Chapter 2: Postponed
Adder Halls: 5%
(This post was last modified: 03-10-2012, 03:42 AM by DaAinGame.)
03-10-2012, 03:06 AM
Find
Adrianis Offline
Senior Member

Posts: 620
Threads: 6
Joined: Feb 2012
Reputation: 27
#5
RE: Confused with void Func_Name

(03-10-2012, 03:06 AM)DaAinGame Wrote: Adrianis, I can't tell if your post helped me or confused me even more....
Thats Ok, it took me a little while to get used to, havn't seen a script work like this before, so I might not be able to explain it too well, but no one else is so what the hell I'll try at least Smile

Your 'Fade' function is fine. So, there are 'Engine functions' (the page for which I previded before) such as 'AddTimer' and 'AddEntityCollideCallback'. The conditions for these must be filled in with the relevant information, so where the timer function is 'AddTimer(string& asName, float afTime, string& asFunction);' you need to replace the strings and integers (inc. floats) etc with values like ("T1", 15, "TimerFunc")

Now the AddEntityCollideCallback, which I think is what you are using for the 'LookRocks' function. When this is added within the void OnStart(), needs the strings/integers etc filled in. It calls to a function that you define.

Where you define your function, created by the callback part of the previous engine function used (AddEntityCollideCallback), there are a set of conditions, which you have written below,

"void LookRocks(string &in asParent, string &in asChild, int alState)"

This is correct. You do not replace these strings/ints (variables) because their values are taken from the engine script which called it, and this means you only need to reference the variable name. The variables themselves are as follows,
asParent = The entity (can be "Player") that will collide with the other entity, or 'Child'
asChild = The entity (or area) that will be collided with by the Parent
alState = Whether the function is called on the start of the collision (1), at the end (-1) or either start/end (0)

"how do I figure out what does the second part means?"
- It is taken from the function that called it

Now, your function is called 'LookRocks', if you are using a 'Look at' callback such as SetEntityPlayerLookAtCallback, then the syntax for the callback function (your 'LookRocks' function) should be (string &in asEntity, int alState).

Let me give you some context by showing you what I've done,


void OnStart()
{
SetEntityPlayerLookAtCallback("work_desk_worn_2", "LookAtCandles", true);
}
This is the engine function to call to another function when the player looks at the desk

void LookAtCandles(string &in asEntity, int alState)
{
SetLampLit("candlestick02_1", false, false);
SetLampLit("candlestick02_3", false, false);
CreateParticleSystemAtEntity("candlestick_1_gust", "ps_dust_push.ps", "ScriptArea_4", true);
CreateParticleSystemAtEntity("candlestick_3_gust", "ps_dust_push.ps", "ScriptArea_5", true);
PlaySoundAtEntity("wind", "27_wind.snt", "Player", 0, false);
SetLightFlickerActive("PointLight_1", true);
SetLightFlickerActive("PointLight_2", true);
AddTimer("T1", 0.4, "CandleLightOut");
}
In this callback function, I actually ignore the asEntity and alState (which make up the condition for this callback function) variables as they have no relevance to what I want to do with the function. At the end, I use AddTimer to create a call out to another callback function, below

void CandleLightOut(string &in asTimer)
{
SetLightVisible("PointLight_1", false);
SetLightVisible("PointLight_2", false);
}
Note how the condition variable has changed due to the different engine function I used to call to this function. Again, I have not used the asTimer variable. However, if I wanted to I could use the asTimer variable in the following way

void CandleLightOut(string &in asTimer)
{
if (asTimer == "T1")
{
SetLightVisible("PointLight_1", false);
SetLightVisible("PointLight_2", false);
}
}

Here I use the asTimer variable, which holds the name of the timer that was used initially to call this function, to check whether the timer calling to this function is the correct timer. I can actually reference whatever variable is pulled into this function by the callback, which means you can have 1 callback function used multiple times by other functions, that work regardless of what entity/light etc is affected

If you look at the Engine functions here (http://wiki.frictionalgames.com/hpl2/amn..._functions) you will see that where functions are used that call to other functions, such as the timer or look at callbacks, the variable names that make up the conditions for that function are defined in the description of the function, there is no way you can guess or choose yourself unfortunately, you must use this page as a reference.

I hope that clears things up, however, looking at the amount written I have a feeling it might not Smile

(This post was last modified: 03-11-2012, 04:40 AM by Adrianis.)
03-11-2012, 04:33 AM
Find
DaAinGame Offline
Member

Posts: 90
Threads: 11
Joined: Mar 2012
Reputation: 4
#6
RE: Confused with void Func_Name

Thank you, cleared some things up for me, but yesterday I finally caught onto it. Can't believe I struggled with it so much at the start, but it sure seems that once you catch on to how you do it, its really simple. Thanks for taking the time to write all of that out however, still filled in a few holes that I still didn't quite understand. Already on part 3/6 of my custom story. If anything is going to slow me down now, its going to be figuring out the layouts for the last 3 maps.

Realm Of Another Chapter 1: http://www.frictionalgames.com/forum/thread-14142.html
Realm Of Another Chapter 2: Postponed
Adder Halls: 5%
03-11-2012, 08:00 PM
Find




Users browsing this thread: 2 Guest(s)