724 posts
Location
Kinda lost
Posted 05 October 2013 - 03:03 PM
Got 5 questions i was unable to get answers by testing.
1) Does turtle in movement still receives modem messages? I realize movement functions discard event queue but with parallel i can have one function for movement and other for wireless. I was unable to get 100% sure result on this one.
2) Would 10-15 turtles sending 10 character string modem messages to each-other (all on same frequency) every 2-5 sec have any negative effects in SMP situation? My test didn't show any negatives but i want to be sure.
3) Would effects of 2) connected with movement and/or mining by those turtles have greater effect?
4) Again in case 2) would using Top Level Coroutine Overwrite to get rid of rednet coroutine lessen negative effect? I am thinking about using it anyways cause all those rednet_message events are ignored in this design.
5) What about 50 turtles? :P/>
8543 posts
Posted 05 October 2013 - 03:50 PM
1. Yes.
2. This depends on how crappy the server is. 2-5 seconds shouldn't show an deleterious effects on most servers.
3. More computation/work being done by the server will always result in decreased tick rate, even if it isn't noticeable, or isn't decreased to below 20t/s.
4. Possibly, but see 3.
5. See 3.
724 posts
Location
Kinda lost
Posted 10 October 2013 - 05:34 PM
Got 2 more fast questions that are not worth new Topic i feel.
1) Is there a way to detect if program was run as startup or executed from shell?
I mean difference between auto-run and player run startup file.
2) Is there a way to detect if player is holding down ctrl+s or ctrl+r? I know i cant stop those events but in this one sec i could stop movements calls so my positioning script would not loose his position again. I tried capturing ctrl and r key events but that didn't work.
101 posts
Location
Norway
Posted 10 October 2013 - 06:28 PM
1'st i do not believe there is a difference between shell.run and a user started program
2'nd
can't see why this shouldn't work
event, key = os.pullEvent("key")
if key == 29 or key == 157 and key == 19 or key == 31 then
...
end
7083 posts
Location
Tasmania (AU)
Posted 10 October 2013 - 07:15 PM
1) Is there a way to detect if program was run as startup or executed from shell?
I mean difference between auto-run and player run startup file.
Scripts can call scripts. You could create a startup script that simply calls your main program with a special parameter/arguement, tipping it off as to how it was being launched.
2) Is there a way to detect if player is holding down ctrl+s or ctrl+r? I know i cant stop those events but in this one sec i could stop movements calls so my positioning script would not loose his position again. I tried capturing ctrl and r key events but that didn't work.
Other things can restart turtles too (eg the Minecraft server rebooting). I suspect you'd be better off rigging your script so that it can correctly determine its position on boot. Since you're using modems anyway you may as well implement a GPS system.
724 posts
Location
Kinda lost
Posted 10 October 2013 - 07:47 PM
Scripts can call scripts. You could create a startup script that simply calls your main program with a special parameter/arguement, tipping it off as to how it was being launched.
Facepalm - I am such idiot to didn't think of that.
Other things can restart turtles too (eg the Minecraft server rebooting). I suspect you'd be better off rigging your script so that it can correctly determine its position on boot. Since you're using modems anyway you may as well implement a GPS system.
Funny thing is i crashed server few times and shut it down brutally, and no problem - positioning system kept position.
But one Ctrl-t or Ctrl-s and stuff gets weird. Like it reboots/shutdowns in middle of turtle movement on purpose . Anyways figured out solution to this one. When you hold Ctrl and press any buttons there are key events but there is no char event - so if i catch key event and verify that char event don't happen then i know program will probably be shutting down under sec - can stop movement functions. Then if nothing happens in like 10s? False alarm resuming movement.
I don't trust GPS systems as a rule. You never know when someone messed with one of those and your turtle decides that best path to destination is trough middle of your base.
8543 posts
Posted 10 October 2013 - 08:12 PM
can't see why this shouldn't work
event, key = os.pullEvent("key")
if key == 29 or key == 157 and key == 19 or key == 31 then
...
end
That condition would never evaluate to true. That line is essentially equivalent to `if false then`.
331 posts
Posted 11 October 2013 - 03:18 AM
can't see why this shouldn't work
event, key = os.pullEvent("key")
if key == 29 or key == 157 and key == 19 or key == 31 then
...
end
That condition would never evaluate to true. That line is essentially equivalent to `if false then`.
would this return false? i understand the if statement is messed up
heres why:
if key == 29 or key == 157 and key == 19 or key == 31 then
go throuh this logically and you get
1. if key == 29 then continue
2. or if key == 157 then continue
the rest just want do it put it brackets like this maybe?
if (key == 29 or key == 157) and (key == 19 or key == 31) then
not sure if thats how you want it but another problem arises: you have an and in there
so it is checking if its key == 29 or key == 157 and key also == 19 or 31 … see the problem key is only one value but you want it to be two
997 posts
Location
Wellington, New Zealand
Posted 11 October 2013 - 03:21 AM
can't see why this shouldn't work
event, key = os.pullEvent("key")
if key == 29 or key == 157 and key == 19 or key == 31 then
...
end
That condition would never evaluate to true. That line is essentially equivalent to `if false then`.
To clarify, you have an "and" instead of an "or"
724 posts
Location
Kinda lost
Posted 11 October 2013 - 04:40 AM
Posting testing code i used that detects ctrl+r or ctrl+s events if someone needs it.
It can be used to detect other ctrl+char combinations if modified.
Left some test os.queueEvent as proof that it rebuilds event queue after its done with what its doing.
Spoiler
--Char testing
local function testforchar(A)
local out=false
local test=keys.getName(A)
local tempT={}
os.queueEvent("1 event"," test1")
os.queueEvent("2 event"," test2")
os.queueEvent("3 event"," test3")
os.queueEvent("4 event"," test4")
os.queueEvent("testchar"..test)
while true do
table.insert(tempT,{os.pullEvent()})
print(unpack(tempT[#tempT]))
if tempT[#tempT][1]=="char" then
if tempT[#tempT][2]==test then out=true end
elseif tempT[#tempT][1]=="testchar"..test then
table.remove(tempT,#tempT) break
end
end
while #tempT >0 do
os.queueEvent(unpack(table.remove(tempT)))
end
return out
end
--Program Start
sleep(0.01)
local event={}
while true do
event={os.pullEvent()}
print(unpack(event))
if event[1]=="key" then
if event[2]==19 or event[2]==31 then
if not testforchar(event[2]) then
print("Its happening")
else
print("Normal letter")
end
end
end
end