- ComputerCraft | Programmable Computers for Minecraft
- → Cruor's Content
Cruor's Content
There have been 9 items by Cruor (Search limited from 10-February 22)
#213418 [1.7.10] Sleep sleeping for incorrect amount of ticks
Posted by
Cruor
on 10 April 2015 - 05:19 PM
in
Bugs
MC 1.7.10, CraftOS 1.6, ComputerCraft1.65
Bug is also in latest beta (1.74pr20)
When sleeping for 0.2s towards 0.65s included, it adds another tick. Meaning a 0.2s sleep actually is 0.25, and so on.
Output from test program, first arg is sample count, second is time. (Yes, it is consistent with higher sample count)

Edit:
After decompiling the source, the problem seems to be in OSAPI.java
Digging deeper, said method is called from ServerComputer.java
Edit 2:
Proof that this is due to the use of doubles, and not tick alignment (or whatever other magical phenomenon you specify it under).
https://ideone.com/hqthf8
Can this be changed to ticks represented in integers instead?
Bug is also in latest beta (1.74pr20)
When sleeping for 0.2s towards 0.65s included, it adds another tick. Meaning a 0.2s sleep actually is 0.25, and so on.
Output from test program, first arg is sample count, second is time. (Yes, it is consistent with higher sample count)

Edit:
After decompiling the source, the problem seems to be in OSAPI.java
public void advance(double dt) {
Map var3 = this.m_timers;
synchronized(this.m_timers) {
this.m_clock += dt;
Iterator previousTime = this.m_timers.entrySet().iterator();
while(previousTime.hasNext()) {
Entry entry = (Entry)previousTime.next();
OSAPI.Timer previousDay = (OSAPI.Timer)entry.getValue();
previousDay.m_timeLeft -= dt;
if(previousDay.m_timeLeft <= 0.0D) {
this.queueLuaEvent("timer", new Object[]{entry.getKey()});
previousTime.remove();
}
}
}
The inaccuracy is caused by the use of doubles at the m_timeLeft -= dt;Digging deeper, said method is called from ServerComputer.java
public void update() {
super.update();
this.m_computer.advance(0.05D);
this.m_changedLastFrame = this.m_changed || this.m_computer.pollChanged();
this.m_computer.clearChanged();
this.m_changed = false;
++this.m_ticksSincePing;
}
Edit 2:
Proof that this is due to the use of doubles, and not tick alignment (or whatever other magical phenomenon you specify it under).
https://ideone.com/hqthf8
Incase Ideone doesn't keep paste around
/* package whatever; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
public static void main (String[] args) throws java.lang.Exception
{
/* test 1 */
double left1 = 0.65;
int foo1 = 0;
while (left1 > 0.0d) {
left1 -= 0.05d;
foo1++;
}
System.out.println(foo1);
/* test 2 */
double left2 = 0.7;
int foo2 = 0;
while (left2 > 0.0d) {
left2 -= 0.05d;
foo2++;
}
System.out.println(foo2);
}
}Can this be changed to ticks represented in integers instead?
#195633 Shurtle Preview
Posted by
Cruor
on 08 October 2014 - 08:28 PM
in
General
Shurtle is a stack based language for making turtle movement from the shell more convenient.
The project was started because I found the built in `go` program too inconvenient, and wanted something which was easier to use, and more powerful.
So far Shurtle supports more than just basic Turtle movment. It has for loops, while loops and ternary, making it able to do most of your turtle shenanigans.
Documentation and example programs are work in progress.
At the moment the project is still in alpha, and is not publicly available.
The project was started because I found the built in `go` program too inconvenient, and wanted something which was easier to use, and more powerful.
So far Shurtle supports more than just basic Turtle movment. It has for loops, while loops and ternary, making it able to do most of your turtle shenanigans.
Documentation and example programs are work in progress.
Documentation as of 2015-07-26
Stack
The stack is FILO (First In Last Out)
Strings and number literals are pushed to the stack
Any uppercase character is a "Variable" and the variables value will be pushed to the stack
Variables
D: "down"
U: "up"
F: "forward"
I: "inventory"
R: "right"
L: "left"
S: 64 - Stack
H: 32 - Half Stack
Q: 16 - 1/4 Stack
M: "minecraft:"
V: nil - Values during loop is stored here
K: nil - Loop iteration number is stored here
N: "\n"
T: true
A: {} - This is always a empty table
B: {__type = "block"} - A custom type table to "wall" away parts of the stack
X: 0 - X position relative to starting point, forward = x + 1, back = x - 1
Y: 0 - Y position relative to starting point, up = y + 1, down = y - 1
Z: 0 - Z position relative to starting point, right = z + 1, left = z - 1
W: 0 - Direction relative to starting point
G: nil - The amount of fuel in ComputerCraft, the amount of energy in OpenComputers
Operators
Applicable operator methods are checked in order, which is specified in order underneat
For example: `w`(sleep) will allways try to sleep for "n" seconds before it uses the "none" method
Methods in the documentation are by default verbose (pushes values to stack), any not verbose methods will be explicity marked
None of the operators for loops or ternary are verbose, or has return values
Arguments are writtens as their types (string, number, boolean, etc)
If the type is "any" it means it can be any type (besides "block")
If the type is "none" it means that operator method does not take any argument
Operators with no applicable methods will not error, and will be ignored
Math, strings and what not
+
number number
Addition
number string
Concatenation
string number
Concatenation
any table
Append to table
-
number number
Subtraction
s::string strip::string
Remove "strip" from the end of "s", "strip" is a Lua pattern
n::number
-n
table
If captured, pops last element and pushes table and the value onto the stack
Else, removes the last element in the table and puts it back on the stack
^
number number
Power
number table
If the value is nil, a false will be used instead
If captured, pushes the table and the value at the index back onto the stack
Else, puts the value at the index onto the stack
string table
If the value is nil, a false will be used instead
If captured, pushes the table and the value at the index back onto the stack
Else, puts the value at the index onto the stack
!
boolean
Logical not
&
boolean boolean
Logical and
|
boolean boolean
Logical or
%
number number
Modulo
*
number number
Multiplication
string table
Join table into a single string, inserting the delimiter between each value
number string
Repeats the string s for n times
/
number number
Division
s::string sep::string
Split string "s" on "sep", "sep" is a Lua pattern
,
string
If captured, push the string and the string length onto the stack
Else, put string length onto the stack
table
If captured, push the table and the table length onto the stack
Else, put table length onto the stack
n::number
Table with values from 1 to n
.
any
Discard
_
table
Pushes the table, and a shallow copy of it onto the stack
any
Duplicated top value on stack
\\
any any
Swap the two top values on the stack
@
any any any
Rotate the top three values on the stack
(No, I don't even what that means, complain to CJam)
=
any any
Equality check
>
number number
Greater than
table number
Slices the table from n + 1 to end of table
If captured, push the table and the slice back onto the stack
Else, put the slice onto the stack
<
number number
Less than
table number
Slices the table from start to n
If captured, push the table and the slice back onto the stack
Else, put the slice onto the stack
o
any
Not verbose, no return value
Print
w
number
Not verbose
Sleeps for n seconds
none
Not verbose
ComputerCraft: Sleep for 1 tick
OpenComputers: yields once
$
Not verbose (does not affect itself)
The return values of the next operator call will be pushed to the stack
Loops
[
For loop start
Can iterate over tables, strings and numbers
Strings are character wise
Tables are element wise
Numbers are from 1 to n
Variable V will be set to the current iteration value
Variable K will be set to the current iteration index
If the object isn't iterateable it will jump to matching ]
]
for loop end
Will jump back to [ if there is more to iterate
#
Conditional part of while loops
{
While loop start
If the top element on the stack is true (actuall true, not in boolean context) the loop will run until it hits }
Otherwise the loop will end
}
If the loop has a condition mark it will jump back to it, otherwise to the start
(
Continue
)
Break
Ternary
?
If the top value on the stack is true (actuall true, not boolean context) it will run code until :, ; or end of file
If it is false it will jump to :
:
If the top value of the stack was true, jump to ; or end of file, otherwise do nothing
;
Clean up dirty black magic
Turtle
All movement is "non blockable", meaning it can fail
f
number
Not verbose, returns true if all movement succeded
Forward for n blocks
none
Not verbose, returns true if movement succeded
Forward
b
number
Not verbose, returns true if all movement succeded
Back for n blocks
none
Not verbose, returns true if movement succeded
Back
u
number
Not verbose, returns true if all movement succeded
Up for n blocks
none
Not verbose, returns true if movement succeded
Up
d
number
Not verbose, returns true if all movement succeded
Down for n blocks
none
Not verbose, returns true if movement succeded
Down
l
number
Not verbose, returns true if all movement succeded
Turn left n times
none
Not verbose, returns true if movement succeded
Turn left
r
number
Not verbose, returns true if all movement succeded
Turn right n times
none
Not verbose, returns true if movement succeded
Turn right
m
string
Not verbose, returns true if anything was mined
Digs in the direction specified, "forward", "up", "down" are valid
none
Not verbose, returns true if anything was mined
Digs forward
p
string
Not verbose, returns true if anything was placed
Places in the direction specified, "forward", "up", "down" are valid
none
Not verbose, returns true if anything was placed
Places forward
a
string
Not verbose, returns true if anything was attacked
Attacks in the direction specified, "forward", "up", "down" are valid
none
Not verbose, returns true if anything was placed
Attacks forward
q
string number number
Not verbose, returns true if successful
Only valid direction is "inventory"
Transfers n items from current slot to slot m
string number
Not verbose, returns true if successful
if the direction specified is "forward", "up" or "down", drops n items from the current slot in the direction
If the direction specified is "inventory", it transfers the stack in the current slot to slot n
string
Not verbose, returns true if successful
Drops the stack in the current slot in the direction specified, "forward", "up", "down" are valid
number
Not verbose, returns true if successful
Drops n items from the current slot forwards
none
Not verbose, returns true if successful
Drops the stack in the current slot forwards
t
string number
Not verbose, returns true if successful
Takes n items from the direction specified, "forward", "up" and "down" are valid
string
Not verbose, returns true if successful
Takes a stack of items from the direction specified, "forward", "up" and "down" are valid
number
Not verbose, returns true if successful
Takes n items from the front
none
Not verbose, returns true if successful
Takes a stack of items from the front
c
number
Item count in slot n
none
Item count in current slot
s
string
Not verbose, returns selected slot or false if not successful
Selects a slot the item specified
Prioritizes non full slots over full ones
For example "minecraft:wheat_seeds", "minecraft:iron_ore"
number
Not verbose, returns selected slot or false if not successful
Selects slot n
none
Gets the current selected slot
e
string
Not verbose, returns true if item was equip
Equips item in current slot to the side specified, "left" and "right" are valid sides
none
Not verbose, returns true if item was equip
Equips the item in the current slot to the right hand
"Yea, I'm just going to decide... And turtles are right handed" -Cruor
g
number
Not verbose, returns true if item is a fuel
Refuels using n items from the current slot
none
Not verbose, returns true if item is a fuel
Refuels with all the items in the current slot
i
When no item/block is present, the block is "minecraft:air", and the damage value is 0
number
Inspects the item in slot n
Pushes the damage value and block name
string
Inspects in specified direction
If direction is "forward", "up" or "down" it will check the block in that direction
If direction is "inventory" it will inspect the current slot
Pushes the damage value and block name
none
Inspects forward
Pushes the damage value and block name
Example farm program
#T{
'Starting farming'o
#T{
DiM'wheat'+=\7=&?
1s
Dm
;
M'wheat_seeds'+ $s?
Dp
;
$f!?
GS<?
'Feed me :<'o
Qs
#GS<{
5w
g
}
;
W0=?
r
$f!?
)
;
r
:
l
$f!?
)
;
l
;
;
}
Zb
l
Xb
#M'wheat'+ $s{
Uq
}
'Waiting for plants'o
600w
}
Old preview video
At the moment the project is still in alpha, and is not publicly available.
#194819 What are you planning to do with the new Computercraft 1.64 features?
Posted by
Cruor
on 30 September 2014 - 08:37 PM
in
General
nitrogenfingers, on 29 September 2014 - 01:02 PM, said:
Cruor, on 29 September 2014 - 10:11 AM, said:
Yes it makes it easier, and it breaks the forth wall. In my honest opinion these are borderline overpowered functions and should at the very least be posible to turn off(and as far as I know there is no config option).
Out of curiosity what exactly makes them overpowered? You can create the exact same effect by having a bunch of compareTo's as you say, but the difference is this is substantially easier to set up. I'm not sure "easy" and "powerful" are necessarily equivalent...
Not that I'm saying I disagre with you, I'm still not sure what to make of the changes. But I'd like to use these to update my butler, make him a bit more efficient and provide more feedback to the user over what's happening.
I mean it simplifies stuff way to much. Writing stuff to interact with blocks and items is way to simple now.
For example, here is some pictures of my proof of concept sorting system: http://imgur.com/a/56tlB
Code is 90 lines, nothing is hardcoded, turtles are configured by putting items in various slots.
The amount of time used to set up the system is around two minutes, it has NONE of the limitations of a pre 1.64 sorting system.
I can put down as many turtles as I want, support as many items as I want per turtle side, and even supports items with different damage values.
Way to powerful and easy to use in my honest opinion.
#194706 What are you planning to do with the new Computercraft 1.64 features?
Posted by
Cruor
on 29 September 2014 - 10:11 AM
in
General
Yes it makes it easier, and it breaks the forth wall. In my honest opinion these are borderline overpowered functions and should at the very least be posible to turn off(and as far as I know there is no config option).
Not to mention that it makes clever setups and use of compare and compareTo redundant.
Not to mention that it makes clever setups and use of compare and compareTo redundant.
#194699 What are you planning to do with the new Computercraft 1.64 features?
Posted by
Cruor
on 29 September 2014 - 07:39 AM
in
General
First thing i'm going to do is check for a config option to turn off the new functions, and if there isn't one, I will make an ASM patch to get one. I do not approve of the new functions, what so ever...
It's one of the things I loved about turtle's design, the fact that they were so simple. Having to compare Blocks/items and use refuel(0) and craft(0) to figure out what stuff is.
It's one of the things I loved about turtle's design, the fact that they were so simple. Having to compare Blocks/items and use refuel(0) and craft(0) to figure out what stuff is.
- ComputerCraft | Programmable Computers for Minecraft
- → Cruor's Content



