Fandom

CraftStudio Wiki

Tutorials/Stopping Gameplay for a certain amount of time

56pages on
this wiki
Add New Page
Comments0 Share


This simple tutorial will show you how to stop gameplay for a set amount of seconds, using scripting.

This will literally freeze the game for a specified amount of time.



Wait() FunctionEdit

To freeze the game, create a simple function like so:


function Behavior:wait(seconds)	
        local _start = os.time()
	local _end = _start+seconds
	while (_end ~= os.time()) do
        -- whatever --
	end
end

What this will do is "Wait", obviously. You can easliy call this function from anywhere in the script, however you would like.

An example of this would be:

function Behavior:Awake()  

end

function Behavior:Update()

if CraftStudio.Input.WasButtonJustPressed( "u" ) then
    
        Behavior:wait(5)
        print "Aww yeehaw!"
    
    end


end

function Behavior:wait(seconds)	
         local _start = os.time()
 	local _end = _start+seconds
 	while (_end ~= os.time()) do
         -- whatever --
 	end
 end



 

This script will, upon pressing the "u" key, freeze the game for 5 seconds and then print "Aww yeehaw!" to the console.

Happy CraftStudioing! --Wolfbanejackal

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.