Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
So im really new to this, and I dont know why it isnt working
Ive googled all around the place, all I can find is that you should put an end somewhere but I dont know where.
Power = peripheral.wrap("ic2:oldmfsu")
mon = peripheral.wrap("monitor_0")
local maxPower = 0
local curPower = 0
local perPower = 0
monX.monY = mon.getsize()
function checkpower()
etc
I expect it to count the number of energy that is stored.
The error message tells you that mon is nil. That means that peripheral.wrap("monitor_0") returned nil instead of the expected table.
Indexing a nil value is not allowed because it doesn't make sense. Hence Lua complains about your attempt.
https://www.computercraft.info/wiki/Peripheral.wrap
Function peripheral.wrap
Returns a table containing functions pointing to the peripheral's
methods, which can then be called as if using peripheral.call(side,
method). If no peripheral is found at the specified side, returns
nil instead.
So check wether mon is nil befor you index it and maybe print an error message else.
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
Here is the line where debugger stops:
let ystart = 24+Int((keyWindow?.safeAreaInsets.top)!)
And the bug comment: Thread 1: Swift runtime failure: force unwrapped a nil value.
I would add that the function above is executed every second. Maybe this will clarify the situation a bit.
Without more context, it‘s hard to find the real issue but at least we know, keyWindow hasn’t been set yet.
yourMainWindow.makeKeyAndVisible() will set the keyWindow. It seems like the failing line is executed before makeKeyAndVisible() and therefore it is still nil.
https://developer.apple.com/documentation/uikit/uiapplication/1622924-keywindow
As mentioned in the comments, always think twice when force-unwrapping an optional, unless you are 100% sure it cannot become nil.
Syntactic sugar:
If you need to set a value that depends on an optional, you should also think about a fallback/default if the optional is nil. Using the coalescing operator (??) helps to avoid nil-check-if-statements like
let ystart = 24+Int(keyWindow?.safeAreaInsets.top ?? yourDefaultValue)
I think I fixed, but I still don't understand the reason behind this problem.
I added simple if statement like if (keyWindow?.safeAreaInsets.top != nil) {}
This question already has answers here:
Calling a Method From a String With the Method's Name in Ruby
(4 answers)
Closed 3 years ago.
I have a table of scores that need processing at certain points. I am trying to avoid having walls of repetitive code so I am trying to get the values dynamically just by sending in the metric value but I cannot seem to get the syntax right and wasn't even sure how to properly search for this.
A typical value I need is something like this
s = score.total_weighted_strategic_values_score
All of these have the same structure to the name but one part changes based on the metric, so I have been trying something like this
s = score.total_weighted_"#{metric}"_score
Where metric is equal to a string strategic_values or whatever the metric is named.
This throws a syntax error, however, and I cannot find anything else to try. any help would be greatly appreciated, thanks!
You need to use public_send:
s = score.public_send("total_weighted_#{metric}_score")
Some more reading on it:
http://vaidehijoshi.github.io/blog/2015/05/05/metaprogramming-dynamic-methods-using-public-send/
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
[ERROR] Lua is unable to understand file "darkrp_customthings/jobs.lua" because its author made a mistake around line number 21.
The best help I can give you is this:
There is an opening '(' bracket at line 20, but this bracket is never closed or not closed in time. It was expected to be closed before the '=' at line 21.
Can someone help correct the errors in my code?
The code:
https://www.dropbox.com/s/o2w9jx2kqefu2n0/job%20.txt?dl=0
You wrote something like this (simplified):
TEAM_TERRORIST = AddExtraTeam(
"Terrorist",
customCheck = function(ply) end
)
This is not valid syntax in Lua, where there are no named parameters.
Maybe the AddExtraTeam function expects a table instead? E.g. this is valid syntax:
TEAM_TERRORIST = AddExtraTeam{
"Terrorist",
customCheck = function(ply) end
}
Not sure this is the right solution though, I don't know DarkRP.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
How can I play 20 wma files on delphi using Tmediaplayer, one after another in a continues loop until the program is closed ? I already tried using a timer for each file , but I keep failing. I have 20 songs that I'd like to play in the background while the rest of the program runs.
Put the filenames into a list. Set the TMediaPlayer.FileName property to the first filename in the list, set the TMediaPlayer.Notify property to true, and call TMediaPlayer.Play(). When the TMediaPlayer.OnNotify event signals playback has finished, you can assign the next filename in the list to TMediaPlayer.FileName, reset TMediaPlayer.Notify to true, and call TMediaPlayer.Play(). Repeat for each filename in the list. One you have played the last filename, start over with the first filename.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
I'm new in delphi and i thought it might be safer to swap object names in loop instead of copying whole block for each object. So I need to use variable name as some objects name.
Here is an example of what i tried and what i am trying to do.
Var
YazGrid: TStringGrid;
I defined a variable for grid name as above and i am trying to use like this:
Some Loop
begin
if a_variable>=10 then
YazGrid:=form1.StringGrid1
else
YazGrid:=form1.StringGrid2;
YazGrid.Cells[1,i] := 'SomeText';
End;
As the result- it comes out with the "Access Violation" error. How should i do this?
Thanks in advance.
Everything looks right in your code.
Make sure that variable "i" in bound. Anyway, even if "i" out-of-bound, this shound't raise Access Violation.
Tested with Delphi XE2 and XE4.
I suppose that error occure in code that not showed in your sample.