vlc.playlist.loop automation - lua

Basically I have this .lua code in my vlc extension, now I am having problems in setting the VLC repeat automatically to loop all in a playlist.
I have tried setting it into "all", 0, 1, 2, true, "TRUE" but it does just not set the playlist's loop value into "all".
I also cannot get the playlist loop value. I tried object.playlist().loop, vlc.playlist.loop.
I read the VLC's Lua Script and Extensions page but I still cannot get what is supposed to be that
<status>
value or any of its acceptable strings.
function trigger()
vlc.playlist.stop()
vlc.playlist.sort("random")
vlc.playlist.goto(0)
--vlc.playlist.repeat_(<status>)
--vlc.playlist.loop(<status>)
vlc.playlist.play()
end

Solved it, thanks to Vyacheslav and Piglet
this would now set the vlc playlist loop to loop all, but I cannot print or vlc.msg.info the value of playlist.loop though. But it works in the end.
function trigger()
vlc.playlist.stop()
vlc.playlist.sort("random")
vlc.playlist.goto(0)
playlist = vlc.object.playlist();
if vlc.var.get(playlist,"loop") == false then vlc.playlist.loop() end
vlc.playlist.play()
end

I have not tried it but following the documentations logic status should be either nil, true or false. If nil (or no argument) it will toggle the current state. true will enable, false disable loop or repeat.
Not sure why you expect loop to be "all".
Did you remove the -- in front of the respective line?
I assume setting both doesn't make sense. And they will toggle each other internally?

In common case, if you do not know how it properly works, it is possible to search such code in github.com.
In your case, you can use this:
https://github.com/search?utf8=%E2%9C%93&q=vlc.playlist.loop+language%3ALua&type=Code&ref=searchresults
As you can see,
you can use such code:
elseif command == "pl_loop" then
vlc.playlist.loop()
elseif command == "pl_repeat" then
vlc.playlist.repeat_()
or
elseif c == 'loop' then
if vlc.playlist.loop(v) then
vlc.playlist.repeat_('off')
end
elseif c == 'repeat' then
if vlc.playlist.repeat_(v) then
vlc.playlist.loop('off')
end

Related

ROBLOX - If statement won't run inside of while loop?

I've run into something really strange. I was originally trying to make a music script (more like system, tbh) and it had the same problem. Now I have boiled it down to a simple test:
while true do
if script.Parent.musicstate.Value == true then
print("Play")
elseif script.Parent.musicstate.Value == false then
print("Stop")
end
wait()
end
When I run it, it will either only print "Stop" or only print "Play." The string it will print will depend on the value of the bool value when the game starts, as in it does not change what it prints depending on the current value. All help will be appreciated, thanks!
The structure, SongScript is what is running:
Never ever make such an infinite loop crashing your whole system! There is a lot more efficient way to do. You have the problem due to the fact that the script would auto break so it won't crash your whole system.
script.Parent.musicstate.Changed:Connect(function()
if script.Parent.musicstate.Value == true then
print("Play")
elseif script.Parent.musicstate.Value == false then
print("Stop")
end
end)

gmod GameMode Lua. IsPlayer retuning nill value

I'm trying to make a gmod gamemode. In my init.lua I wanted it so that way team members can't hurt each other. So I used this code
function GM:EntityTakeDamage( target, dmginfo )
if ( target:IsPlayer() and dmginfo:IsPlayer() ) then
if (dmginfo:Team() == target:Team()) then
dmginfo:ScaleDamage( 0.0 ) // Sets damage to 0
end
end
end
However it's giving me the error telling me that IsPlayer() is a nil value even though it should be returning a boolean. It points to no other lines other then the line with IsPlayer() and it's saying it is IsPlayer()
you have a typo in line 3. dminfo
You should narrow down which of your multiple IsPlayer() calls actually is nil
dmgInfo is a CTakeDamageInfo which has no function IsPlayer()
single line Lua comments are opened with --, not //
https://wiki.garrysmod.com/page/Category:CTakeDamageInfo
If you call a function and it says its nil, then check if it even exists. Or even better, check this befor you use the function in the first place.
And to prevent you from coming back in a minute, CTtakeDamageInfo also does not have a function Team() as well.
Check out CTDamageInfo:GetAttacker()

Computercraft lua change value later

ok, Im almost completely new to lua and computercraft but I have alot of creativity. I'm trying to write code that will reprint a variable every second. here is what I have so far:
display = "Loading..."
While true do
sleep(1)
term.clear()
term.setCursorPos(1,1)
print (display)
end
sleep(3)
display = "hello"
I want to use it to render a 2d game, the "display" variable would change often and thus why i want it to be updated every second.
It does indeed refresh every second when I run the code but for some reason I cant seem to get the "display" variable to change after 3 seconds to test it.
What am I doing wrong?
while true is an infinite loop. The script never reaches sleep(3).
Perhaps you want to replace while true with for i=1,3.
I am not experienced in Lua, but this might be a solution: answer on SO
In the UI thread, run:
while ((status=lua_resume(L_coroutine, 0)) == LUA_YIELD) {
semaphore_wait(); /* whatever the appropriate C# call is */
}
"Wait for response" should look something like:
while not results[my_result] do
coroutine.yield()
end
The "incoming message" function should look like the following in Lua:
results[cur_result]=parsed_message

LUA - OnUpdate shift modifier

I'm changing something in an Addon for World of Warcraft which are written in Lua.
There is a simple boolean variable which determines if some "all" frames are shown or only specific one.
So when = true then it will only show specific frames
when = false it will show all frames
I want to make a modifier with the shift key to show all frames when the shiftkey is pressed and hide them again when shift is realeased.
if IsShiftKeyDown() then
cfg.aura.onlyShowPlayer = false
else
cfg.aura.onlyShowPlayer = true
end
This is my very simple solution for it which works. The problem here is though it only works on starting of the script. You see in WoW everytime the interface gets loaded it will run the script if not told otherwise. That is not very efficent because I would send my user into a loadingscreen.
OnUpdate should fix my problem here which will run this specific code everytime a frame gets rendered which is pretty handy and is what I want to accomplish.
So this is what I made
local function onUpdate(self,elapsed)
if IsShiftKeyDown() then
cfg.aura.onlyShowPlayer = false
else
cfg.aura.onlyShowPlayer = true
end
end
local shiftdebuffs = CreateFrame("frame")
shiftdebuffs:SetScript("OnUpdate", onUpdate)
My problem is now that it doesn't work. I new to the onUpdate stuff and only copy pasted it from another addon I did which worked fine.
Right it goes straight to = false, which is only happening I think because it is the default.
thanks for the help
Right it goes straight to = false, which is only happening I think because it is the default.
No, there is no "default" branch in the if statement. For the control to get to the then branch the condition has to be evaluated to true. You need to check the logic, but if the script executed cfg.aura.onlyShowPlayer = false, it means that IsShiftKeyDown() was evaluated as true.

Having trouble with some computercraft/lua code

Hi I want my lua code in Computercraft to allow the user to turn the redstone signal on/off by right clicking on a monitor on top, but I can't get it to work.
monitor = peripheral.wrap("top")
monitor.clear()
monitor.setTextColor(colors.red)
monitor.setCursorPos(1, 1)
monitor.setTextScale(1)
monitor.write("Hello")
function rubber()
monitor.setCursorPos(1, 2)
monitor.clearLine()
if rs.getOutput("right", true) then
monitor.write("Rubber farm is on")
elseif rs.getOutput("right", false) then
monitor.write("Rubber farm is off")
end
local event = { os.pullEvent() }
if event == "monitor_touch" then
if rs.getOutput("right") == true then
rs.setOutput("right", false)
else
rs.setOutput("right", true)
end
else
write("test")
end
rubber()
end
Right now all it displays is 'hello' and I don't know how to fix it, anyone know how? Also I'm a beginner at Lua so I've probably made some pretty simple mistakes. Thanks
local event = { os.pullEvent() }
if event == "monitor_touch" then
os.pullEvent returns a tuple. In your code, you're packing this tuple into a table. That's fine, but you then compare that table to a string. Tables can't be equal to strings - they're a table. Either don't pack the tuple into a table, and keep the first return value (the type):
local event = os.pullEvent()
if event == "monitor_touch" then
Or extract the first element when comparing
local event = { os.pullEvent() }
if event[1] == "monitor_touch" then
The problem is you wanted to have that function infinitly looping, but you have not called your function outside your function.... also you should look into using while loops
while true do
//stuff here
end
just add
rubber()
to the last line after your last end tag.
You have to call the function.
rubber()
You need to close your function
function rubber()
monitor.setCursorPos(1,1)
monitor.clearLine()
end
The end is it you need to make this little word
this is a simple fix, simply add rubber() after you finish the function rubber, cause while you have created the function rubber, you have not called for it to start yet.
The "monitor_touch" event is what you should be using. Also, make sure the monitor you are using is an advanced monitor (the one with the yellow border).
If you need help in understanding the event, check out this page: http://computercraft.info/wiki/Monitor_touch_(event)

Resources