I'm attempting to write a script in LUA for the Minecraft mod ComputerCraft. It's supposed to send a turtle down, mine a hole, and place ladders before returning to the surface. I'm trying to make an error display when the turtle doesn't have enough ladders, but I'm receiving an error that prevents it from running. "mineDown :18: attempt to compare string with number expected, got string."
-- This gets the user to tell the turtle how far to dig down
print('How far down should I go?')
distDown = io.read()
distMoved = 0
ladders = turtle.getItemCount(13)
-- Check if the number of ladders is less than the distance needed to move. If so, returns error.
turtle.select(13)
if ladders < distDown then
error('Not enough ladders!')
end
The error means that ladders is number and distDown is a string. You need to convert them to the same type. For example to convert ladders to a string use tostring or distDown to a number use tonumber:
if ladders < tonumber(distDown) then
enter image description here
I just started working on lua scripting since a week. I have a lua file where in the logic needs to be written for a certain condition.
The condition when gets triggered
it does an iteration on one of the fields to change value from
(ABC123-XYZ) to this value
(ABC123#1-XYZ) and it keeps increasing whenever iterations happens (ABC123#2-XYZ)
I need to run a function that removes the # followed by number to change it back to (ABC123-XYZ). Looking for any advice!
Edit 1:
Below is the updated code that is written Thanks to #Piglet
I have another scenario if therr are two hashes in the variable.
local x = 'BUS144611111-PNB_00#80901#1555-122TRNHUBUS'
local b = x:gsub("#%d+","")
function remove_char(a) a=a:gsub("#%d+","")
return a;
end if string.match(x,"#")
then print('function')
print(remove_char(x));
else print(x);
end
Expected output should be
x = 'BUS144611111-PNB_00#80901-122TRNHUBUS' for the aforesaid variable
local a = "ABC123#1-XYZ"
local b = a:gsub("#%d+", "")
this will remove any # followed by or one more digits from your string.
I'm trying to compute a new variable on SPSS using the menu (tramsform -> compute variable) and an error message appears saying
Text value too long for the current server locale
Do they mean the Numeric Expression I wrote (pasted below)?
If so - is there anything I can do other than making a new variable for every step in the process? Don't really want to compute 10 different variables just to make the one I need...
((LAB_TEST_CD = 62112)&(((LAB_RESULT > 8)&(SAMPLE_DATE < 20111103))
|((LAB_RESULT > 7)&(SAMPLE_DATE >= 20111103))))
|((LAB_TEST_CD = 62111)
&(((LAB_RESULT > 30)&(SAMPLE_DATE < 20140112))|((LAB_RESULT > 7)
&(SAMPLE_DATE >= 20140112))))
I have written a rule like
if
the period of 'Request' is more than 0
then
set the date of 'Request' to due_date - 1 Day;
else
set the date of 'Request' to due_date ;
for period values other than 0 it's working fine but when value of period is 0 it just skips whole rule, i.e it neither go to then nor else.
I am using ODM 8.6 and testing through DVS file.
I have tried same thing in ODM 8.5 and it's working fine there
please help in getting this issue resolved.
Did you try with the latest fixpack?
In general it is poor design for rules to use the else construct. Try to split the rule into 2 different rules:
for period of 'Request'>0, and
for period of 'Request'<0.
I'm trying out Folsom for metrics generation in Erlang.
I've created a histogram (slide), how can I get the values out of it? I'm using
(test#SebMaynardSL2)1> folsom:start().
(test#SebMaynardSL2)2> MyMetric = "mymetric",
(test#SebMaynardSL2)3> folsom_metrics:new_histogram(MyMetric, slide).
And tried putting some values in it:
(test#SebMaynardSL2)4> [ folsom_metrics:notify({MyMetric, V}) || V <- lists:seq(1, 10) ].
But getting the values out (with folsom_metrics:get_metric_value/1) seems to be return the results in rather a strange order:
(test#SebMaynardSL2)5> folsom_metrics:get_metric_value(MyMetric).
[4,5,8,9,3,10,2,7,6,1]
If I wait a while (60 seconds, the default slide window time) and do it again, I don't necessarily end up with a metric value in the same order.
How should I get the values out of Folsom to use for (say) graph generation? I did consider putting {now(), V} instead of just V in my notify, and then sorting the returned result set by the first tuple value, but it seems odd that the results are coming back (or rather, are getting written) in a weird order, and Folsom is keeping track of the time of events anyway (to make it "slide").
This is using Folsom 0.7.4, with Erlang R16B
Thanks!
Rather oddly, after a fresh clone and checking out tag 0.7.4 again, running the commands from the question gives the results in the correct order:
(test#SebMaynardSL2)5> folsom_metrics:get_metric_value(MyMetric).
[1,2,3,4,5,6,7,8,9,10]
Perhaps this wasn't an issue after all. No idea why it was generating such oddities the other day.