Script help - 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: Script help (/thread-9452.html) |
Script help - DRedshot - 07-28-2011 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 RE: Script help - palistov - 07-28-2011 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 Code: void ParentFunction(string &in asEntity, string &in asType) //item interaction callback just as an example RE: Script help - DRedshot - 07-28-2011 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 RE: Script help - Your Computer - 07-29-2011 Here's what i used to bang the door three times: Code: string current_door = ""; (07-28-2011, 11:52 PM)DRedshot Wrote: how would i get the return value to use in another part of my script? thanks Code: int func() RE: Script help - palistov - 07-29-2011 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 RE: Script help - DRedshot - 07-29-2011 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. RE: Script help - palistov - 07-29-2011 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. |