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
Script help
DRedshot Offline
Senior Member

Posts: 374
Threads: 23
Joined: Jun 2011
Reputation: 11
#1
Script help

If I wanted to make a subscript which made a door bang a number of times, at a set speed, Is there a way to 'make' my own function to do this.
I know you can call different scripts to run with:
Func();

but is there a way to store integers or strings in these callbacks? This is what I want to do:

Func(string i = asEntity);

void Func(string &in i)
{
// Do Stuff
}

How can I do this? if there is a way?
Thanks

(This post was last modified: 07-28-2011, 09:36 PM by DRedshot.)
07-28-2011, 09:35 PM
Find
palistov Offline
Posting Freak

Posts: 1,208
Threads: 67
Joined: Mar 2011
Reputation: 57
#2
RE: Script help

You identifier would just be 'asEntity'. So just call Func(asEntity) and then in your function, your signature is just string &in 'whatevernameyouwanttoputhereitdoesnothavetobethesame'.

So your basic structure will look like this

void ParentFunction(string &in asEntity, string &in asType)    //item interaction callback just as an example
{
    //some stuff up here
    
    Func(asEntity);
    
    //some stuff down here
}


void Func(string &in mysig)
{
    //stuff in this function
}

07-28-2011, 10:07 PM
Find
DRedshot Offline
Senior Member

Posts: 374
Threads: 23
Joined: Jun 2011
Reputation: 11
#3
RE: Script help

Thanks very much, I've been wanting to do this for a long while! hopefully my scripting will get a lot easier from now on. Thanks.
I may as well ask another question in this thread since its new:
what if instead of using
void func();

i used
int Func();

I know i'd have to use return int;
but what else would i have to do? can any function be an int, or a string for that matter? or do i have to state something. Also, how would i get the return value later?
for example
int MyFunction()
{
// Some scripts
return 1;
}

how would i get the return value to use in another part of my script? thanks

(This post was last modified: 07-29-2011, 12:27 AM by DRedshot.)
07-28-2011, 11:52 PM
Find
Your Computer Offline
SCAN ME!

Posts: 3,456
Threads: 32
Joined: Jul 2011
Reputation: 235
#4
RE: Script help

Here's what i used to bang the door three times:
string current_door = "";

void BangDoorThreeTimes()
    {
        current_door = "front_door";
        AddTimer("door_slam1", 0, "PlaySound");
        AddTimer("door_slam2", 0.5, "PlaySound");
        AddTimer("door_slam3", 1, "PlaySound");
    }

void PlaySound(string &in timer_name)
    {
        if (StringContains(timer_name, "door_slam"))
            PlaySoundAtEntity("hit_wood2", "hit_wood.snt", current_door, 0, false);
    }

(07-28-2011, 11:52 PM)DRedshot Wrote: how would i get the return value to use in another part of my script? thanks

int func()
{
int i = 1;
return i; // or just: return 1;
}

void other_func ()
{
int i = func();
}

Tutorials: From Noob to Pro
(This post was last modified: 07-29-2011, 04:17 AM by Your Computer.)
07-29-2011, 04:13 AM
Website Find
palistov Offline
Posting Freak

Posts: 1,208
Threads: 67
Joined: Mar 2011
Reputation: 57
#5
RE: Script help

I actually wrote this like 4 hours ago but forgot to post it... lol

When calling int MyFunction you do it the same was as calling it as if it were a void function. In your parent function simply put MyFunction(); and you're all set. And no, not all functions can be int or string; if you have an int function it has to return and integer. If you have a string function it has to return a string, and so on. Void functions don't return any values.

You get the return value by calling the function elsewhere. So if you want to get the value later just call the function again. You can store it as a local variable by doing SetLocalVarInt("returnvalue", Func()); and then using the variable elsewhere.

In place of your // some scripts line you would place code which returns different values depending on different conditions. There's little reason to have a function returning a value unless there are different conditions which would change the effect of its parent function. Use if statements for this purpose Smile

(This post was last modified: 07-29-2011, 07:29 AM by palistov.)
07-29-2011, 07:28 AM
Find
DRedshot Offline
Senior Member

Posts: 374
Threads: 23
Joined: Jun 2011
Reputation: 11
#6
RE: Script help

thanks you two, you've helped me out alot!
Also, after reading YourComputer's post about the banging door, can any function have a randomly chosen signature, such as
(string &in asEntity) can be (string &in AnythingIWant)
even if it's an interact callback. Finally, i can't see how the string carries on to the next function, where it says (current_door = "xxxxx")
how does this go onto the next function? is it sent across with the AddTimers?
Thanks for all the help, and sorry for all the questions. You can probably tell that i've not done much programming before, but i pick it up quickly so i appreciate the help.

(This post was last modified: 07-29-2011, 11:17 AM by DRedshot.)
07-29-2011, 11:08 AM
Find
palistov Offline
Posting Freak

Posts: 1,208
Threads: 67
Joined: Mar 2011
Reputation: 57
#7
RE: Script help

Yes you can declare whatever parameter name you want. It can be string &in zabadabadoo if you want. It will not change what the object actually is though. Simply calling it zabadabadoo doesn't change the fact that it refers to the entity involved in the function.

07-29-2011, 01:24 PM
Find




Users browsing this thread: 2 Guest(s)