Difference between revisions of "love.event.wait"

(Add an example)
 
(2 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
{{newin|[[0.6.0]]|060|type=function}}
 
{{newin|[[0.6.0]]|060|type=function}}
Работает как <code>[[love.event.poll]]()</code>, но не выполняется, пока не сработает одно из событий.
+
Like <code>[[love.event.poll]]()</code>, but blocks until there is an event in the queue.
== Функция ==
+
== Function ==
=== Синопсис ===
+
=== Synopsis ===
 
<source lang="lua">
 
<source lang="lua">
 
n, a, b, c, d, e, f, ... = love.event.wait( )
 
n, a, b, c, d, e, f, ... = love.event.wait( )
 
</source>
 
</source>
=== Аргументы ===
+
=== Arguments ===
Нет.
+
None.
=== Возвращает ===
+
=== Returns ===
{{param|Event|n|Имя события.}}
+
{{param|Event|n (nil)|The name of event, or nil if the event is unrecognized.}}
{{param|Variant|a|Первый аргумент события.}}
+
{{param|Variant|a|First event argument.}}
{{param|Variant|b|Второй аргумент события.}}
+
{{param|Variant|b|Second event argument.}}
{{param|Variant|c|Третий аргумент события.}}
+
{{param|Variant|c|Third event argument.}}
 
{{New_feature|0.8.0|
 
{{New_feature|0.8.0|
{{param|Variant|d|Четвёртый аргумент события.}} }}
+
{{param|Variant|d|Fourth event argument.}} }}
 
{{New_feature|0.10.0|
 
{{New_feature|0.10.0|
{{param|Variant|e|Пятый аргумент события.}}
+
{{param|Variant|e|Fifth event argument.}}
{{param|Variant|f|Шестой аргумент события.}}
+
{{param|Variant|f|Sixth event argument.}}
{{param|Variant|...|Последующие аргументы события, если есть.}} }}
+
{{param|Variant|...|Further event arguments may follow.}} }}
== Смотри также ==
+
== Examples ==
* [[parent::love.event (Русский)]]
+
An example that replace <code>[[love.event.poll]]()</code> with this function.
* [[love.event.poll (Русский)]]
+
<source lang="lua">
 +
function love.run()
 +
    if love.load then love.load(love.arg.parseGameArguments(arg), arg) end
 +
 +
    -- Main loop time.
 +
    return function()
 +
        -- Process events.
 +
        if love.event then
 +
            local name, a,b,c,d,e,f = love.event.wait()
 +
            if name then
 +
                if name == "quit" then
 +
                    if not love.quit or not love.quit() then
 +
                        return a or 0
 +
                    end
 +
                end           
 +
                love.handlers[name](a,b,c,d,e,f)
 +
            end
 +
        end
 +
 +
        -- Call update and draw
 +
        if love.update then love.update(0) end
 +
 +
        if love.graphics and love.graphics.isActive() then
 +
            love.graphics.origin()
 +
            love.graphics.clear(love.graphics.getBackgroundColor())
 +
 +
            if love.draw then love.draw() end
 +
 +
            love.graphics.present()
 +
        end
 +
    end
 +
end
 +
</source>
 +
== See Also ==
 +
* [[parent::love.event]]
 +
* [[love.event.poll]]
 
[[Category:Functions]]
 
[[Category:Functions]]
{{#set:Description=Работает как love.event.poll(), но не выполняется, пока не сработает одно из событий.}}
+
{{#set:Description=Like love.event.poll(), but blocks until there is an event in the queue.}}
 
{{#set:Since=000}}
 
{{#set:Since=000}}
  
== Другие языки ==
+
== Other Languages ==
 
{{i18n|love.event.wait}}
 
{{i18n|love.event.wait}}

Latest revision as of 07:51, 19 October 2020

Available since LÖVE 0.6.0
This function is not supported in earlier versions.

Like love.event.poll(), but blocks until there is an event in the queue.

Function

Synopsis

n, a, b, c, d, e, f, ... = love.event.wait( )

Arguments

None.

Returns

Event n (nil)
The name of event, or nil if the event is unrecognized.
Variant a
First event argument.
Variant b
Second event argument.
Variant c
Third event argument.
Available since LÖVE 0.8.0
Variant d
Fourth event argument.


Available since LÖVE 0.10.0
Variant e
Fifth event argument.
Variant f
Sixth event argument.
Variant ...
Further event arguments may follow.

Examples

An example that replace love.event.poll() with this function.

function love.run()
    if love.load then love.load(love.arg.parseGameArguments(arg), arg) end
 
    -- Main loop time.
    return function()
        -- Process events.
        if love.event then
            local name, a,b,c,d,e,f = love.event.wait()
            if name then
                if name == "quit" then
                    if not love.quit or not love.quit() then
                        return a or 0
                    end
                end            
                love.handlers[name](a,b,c,d,e,f)
            end
        end
 
        -- Call update and draw
        if love.update then love.update(0) end
 
        if love.graphics and love.graphics.isActive() then
            love.graphics.origin()
            love.graphics.clear(love.graphics.getBackgroundColor())
 
            if love.draw then love.draw() end
 
            love.graphics.present()
        end
    end
end

See Also


Other Languages