snowwolf
|
  |
| Joined: 23 Nov 2006 |
| Total Posts: 357 |
|
|
| 26 Dec 2011 09:41 PM |
When you start a function, example: ------------------------------------------------- if IntValue.Value == true then something() end ------------------------------------------------- Now since the function is running, in case somethign else happens: ------------------------------------------------- if IntValue.Value == true then something() end
during something() if OtherIntValue.Value == false then <---- that ending something() partytime() <---- starting another function end end <---- extra end because the "during" is like an "if" or a "function" ------------------------------------------------- So is there a way of making a function stop if something happens? Top one is a bad way of describing it but I tried ------------------------------------------------- something() print("hi") wait(1) print("hello) wait(1) print("har") wait(1) end ------------------------------------------------- This means that where ever in that function, it stops and does another function, in this case, partytime()
I dont know if this is confusing or not but please try and help |
|
|
| Report Abuse |
|
|
|
| 26 Dec 2011 09:46 PM |
Do you mean like:
function FirstOne() for i = 1,3 do wait(1) print(i) end SecondOne() end
function SecondOne() print('all done :D') end
FirstOne()
?
-[::ƧѡÎḾḠΰῩ::]-[::Maker of stuff and Helper of Scripting::]- |
|
|
| Report Abuse |
|
|
smurf279
|
  |
| Joined: 15 Mar 2010 |
| Total Posts: 6871 |
|
|
| 26 Dec 2011 09:49 PM |
function FirstOne() for i = 1,3 do wait(1) print(i) end return SecondOne() --nu stack overflow. . . end
function SecondOne() print('all done :D') end
FirstOne()
|
|
|
| Report Abuse |
|
|
snowwolf
|
  |
| Joined: 23 Nov 2006 |
| Total Posts: 357 |
|
|
| 26 Dec 2011 09:49 PM |
| No, thats implying both function 1 and 2 complete their function, Im wondering if, when activating function 1, you can cancel it in the function's process (wherevere) and do function 2 |
|
|
| Report Abuse |
|
|
|
| 26 Dec 2011 09:50 PM |
@smurf
It won't overflow because it's not a recursive function :P If I did
function one() two() end
function two() one() end
one()
Then it would overflow
-[::ƧѡÎḾḠΰῩ::]-[::Maker of stuff and Helper of Scripting::]- |
|
|
| Report Abuse |
|
|
smurf279
|
  |
| Joined: 15 Mar 2010 |
| Total Posts: 6871 |
|
|
| 26 Dec 2011 09:54 PM |
you mean
function makeMe() for i = 1, 10 do print(i) if i == 7 then return a() end end
function a() for i = 8, 10 do print(i) if i == 10 then return trololol() end end print'lllllllllllllllllllllllllllllllllll' end
function trololol() print("makeMeASandwitch") end
or coroutines? |
|
|
| Report Abuse |
|
|
smurf279
|
  |
| Joined: 15 Mar 2010 |
| Total Posts: 6871 |
|
|
| 26 Dec 2011 09:58 PM |
@Swim I know but it took me like a week to figure out one of the major problems in my maze generator was that I wasn't using tail calls and that was causing stack overflow. I fixed the code so that it wouldn't get stack overflow without using tail calls but now whenever I see functions that call on each other I always use 'return function()' |
|
|
| Report Abuse |
|
|