Jump to content


Sewbacca's Content

There have been 15 items by Sewbacca (Search limited from 29-March 23)


By content type

See this member's

Sort by                Order  

#279057 Funny CC error through easy script

Posted by Sewbacca on 30 May 2019 - 08:38 PM in Ask a Pro

Hello guys,

I found out, how to smash a CC computer, so it is unuseable, unless you rebuild it (if labled) or untill you reload your map (i actually don't know how it would react on a server).

However, don't use this script, if you have important data on your CC computer, unless you are in full control of your computer.

I don't think that the code is malicious, cause it will just freeze your CC PC and it won't delete anything, but be carefully while testing it.
Code



Some questions:
Why on earth is it working?
Why on earth is it telling me, that theres an issue resuming bios.lua?
Why on earth cannot i restart the computer?

Is this issue working for you?
My game hung up for a few seconds, untill this error arises (i think 10).

EDIT:
I tested this code a few times and on other PCs:
- Same PC I don't know why, but after i rebuild the PC, i get a too long without yielding
- Another PC I can restart the computer



#278424 Improve class prototype

Posted by Sewbacca on 23 October 2018 - 07:49 PM in Ask a Pro

View PostEveryOS, on 23 October 2018 - 05:14 PM, said:

After making some syntax error fixes and mods I get this

local class = {}
class.new = function(self)
  local rtn = {}
  setmetatable(rtn, {__index = class})
  return rtn
end
class.method = function() end
local class2 = {}
setmetatable(class2, {__index = class})
class2.new = function(self)
  local rtn = {}
  local mt = {}
  for k, v in pairs(class) do mt[k] = v end
  mt.__index = class2
  setmetatable(rtn, mt)
  return rtn
end
local superclass = class:new()
local inheritanceClass = class2:new()
local obj = inheritanceClass:new()
class.method = function(self, var)
  print("Value: ", var)
end
obj:method("hello")

On Mimic I get "Value: hello"

I will look into other metatable values

I said something wrong, i meant, if you copy metatable functions, you will lose inheritance, but for now, i couldn't figure out a inheritance of metamethods.

View PostEveryOS, on 23 October 2018 - 05:46 PM, said:

Here is something:
--A table called class that does class-type stuff
local class = {}
class.__index = class
class.extend = function(self, cclass)
  class2.__index = self
  setmetatable(cclass, cclass)

  return class2
end
setmetatable(class, class)

Here is a script that uses something like this:
--A table called class that does class-type stuff
local class = {}
class.__index = class
class.extend = function(self, cclass)
  cclass.__index = self
  setmetatable(cclass, cclass)
  return cclass
end
setmetatable(class, class)
local function new(val, ...)
local r = ((val.parent or class):extend(val))
r(...)
return r
end
--After class definition
local number = {
__call = function(self, number)
  self.number = number
end,
__add = function(self, val)
  if type(val) == "number" then
   return self.number + val
  else
   return self.number + val.number
  end
end
}
local wholeNumber = {
parent = number,
__call = function(self, val)
   if math.floor(val) ~= val then error("Not whole") end
   self.parent.__call(self, val)
	end,
	__add = number.__add
}
local n = new(number, 4.2)
print("TYPE OF N: "..type(n))
print(n + 5)
print(n + new(wholeNumber, 3))
print(n + new(wholeNumber, 4.2))

Note that metamethods must be manually defined

Can you please explain me what you are trying to show?



#278420 Improve class prototype

Posted by Sewbacca on 23 October 2018 - 03:04 PM in Ask a Pro

View PostEveryOS, on 23 October 2018 - 12:02 PM, said:

Copy the metamethods?

local class = {}
class.new = function()
  local rtn = {}
  setmetatable(rtn, {__index = class})

  return rtn
end
local class2 = {}
setmetatable(class2, {__index = class})
class2.new = function()
  local rtn = {}]
  local mt = {}
  for k, v in pairs(getmetatable(class)) do mt[k] = v end
  mt.__index = class2
  setmetatable(rtn,mt)

  return rtn
end

Just a guess, I don't use metatables much and I might be reading your question wrong...

That would probably work with one downside. If you inherit a class and down change the super class after creating the inheritance class, then it would work properly, but if not, the new method wouldn't be inherited:

superclass = class()
inheritanceClass = class(superclass)
function superclass:method()
end
local obj = inheritcanceClass:new()
function superclass:method(var)
  print("Value: ", var)
end
obj:method("hello")
-- No output, because he has the method



#278415 Improve class prototype

Posted by Sewbacca on 23 October 2018 - 10:27 AM in Ask a Pro

View PostLyqyd, on 20 October 2018 - 02:48 AM, said:

local function magic(t, k)
	local target = t
	while true do
		local value = rawget(target, k)
		if value ~= nil then return value end
		target = rawget(target, "super")
		if target == nil then return nil end
	end
end

local function add(obj, name, parent)
	setmetatable(obj, {__index = magic)
	obj.super = parent
end

Not heavily tested, but gives your objects a "super" field to trace their lineage upward, and an __index metamethod to step through that sequence.

That would allow me, to use a single metable for all my classes right? I think that would work, but I'm not too confident with such a solution cause of the speadloss during a indexing. I would prefer a __index table instead:

function new(parent)
  local obj = setmetatable({}, parent)
  parent.__index = parent
  return obj
end

local obj = new(parentclass)
[Assuming, that parentclass contains all methods, etc.]

This would allow me the following code:
function parentclass:__add(a, B)/>/>/>
  return a.val, b.val
end

A metamethod, setted up in the class itself, but metamethods won't be inherited when i create a inherit class:
local inheritClass = new(parentclass)
local obj2 = new(inheritClass)
--# obj2 won't have a metamethod __add

That's my problem. If i use a overall metatable with an __index method setted to magic, then I could solve this problem,
but I would like to use a table for __index instead, cause of the speed loss, but I will keep your solution in mind, if i can't find another.
Thanks!



#278399 Improve class prototype

Posted by Sewbacca on 18 October 2018 - 01:08 PM in Ask a Pro

Okay, i have the following class definition:

local class = { }
setmetatable(class, class)

--# Standard methods

--# virtual
function class:__call(...)
	--# Call the constructor for a nice and clean syntax (class())
	return self:construct(...)
end

--# virtual
function class:construct(...)
	--# Constructs an object
	local object = { }
	setmetatable(object, self)
	self.__index = self

	local ok, err = pcall(self.init, object, ...)
	if not ok then error(err, 2) end
	return object
end

--# virtual
function class:init()
	--# Standard constructor with no special construction
end

return class

Goal:
--# Constructing
local object = class()
local TestClass = class()
local InheritClass = TestClass()

--# Adding methods

function TestClass:method()
	--# Do stuff
end

--# Adding metamethods

function TestClass:__tostring()
	return "string"
end

The first things are working quite well, also with InheritClass, but the metamethods won't be inherited, because somehow, lua is ignoring the metatable of the metatable.
I could create methods for each metamethods and redirecting to the class itself, but then how would the index method or table work properly?
And with the current design, textutils screws up everything: It can't index a table with an index to itself and having itself as a metatable.

Any help appreciated and thank you for any answer.

Sewbacca



#278391 [Solved] is rainbow text posible?

Posted by Sewbacca on 17 October 2018 - 04:38 PM in Ask a Pro

View PostJummit, on 16 October 2018 - 11:30 AM, said:

Way 2:
Your c table has to be filled with paint color codes
function rainbowWrite(text)
   local textColorString = ""
   local backgroundColorString = ""
   for x = 1, #text do
	  colorString = colorString..c[math.random(1, 15)]
	  backgroundColorString = backgroundColorString.."0"
	  --# the background will always be 0
   end
   term.blit(text, textColorString, backgroundColorString)
end




Well, I'm bored (more precisly, i have other stuff to do, but I'm lazy or procrastinating), and found another way, using gsub. It is maybe faster or shorter than your second way:
local cols = "0123456789abcdef"
local text = "Hello world!"
local function randomReplace(match)
	local i = math.random(1, 16)
	return cols:sub(i, i)
end
term.blit(text, text:gsub(".", randomReplace), text:gsub(".", randomReplace))



#278380 How does your keyboard feels?

Posted by Sewbacca on 15 October 2018 - 08:56 PM in General

View PostKingofGamesYami, on 10 October 2018 - 10:15 PM, said:

Was totally expecting r/mechanicalkeyboards but got this instead.

Hehe :P, I have a rubber keyboard, but it feels like a mechanical (never had a mechanical but that's just what i think it feels like). To be precisly, i have a Microsoft Sidwinder X4 if you are interested.



#278351 How does your keyboard feels?

Posted by Sewbacca on 10 October 2018 - 09:03 PM in General

Intressting. I was wondering what could be the average, because the keyboards and the mice of my friends just feel disgusting.



#278300 How does your keyboard feels?

Posted by Sewbacca on 03 October 2018 - 08:27 PM in General

Just like the title says: How does your keyboard feels like. I mean something like clean, oily or there is a layer of sugar, one centimeter thick.

For me, my keyboard feels a little bit oily, but mostly clean, compared with the keyboards of my friends.



#278230 ASCII - a ASCII visualizer

Posted by Sewbacca on 04 September 2018 - 10:54 AM in APIs and Utilities

ASCII - a ASCII visualizer

Posted Image

What it does:
The program visualizes all chars and give you easy access to the special chars, so you can make your program look fancier very easy.

Usage:
Run ASCII (should work at pocket computers too).
Select your char via arrows or mouse click.
Press backspace to exit the program.
Insert the char inside your program:
local char = "\247"
-- Inserts the 247 char (a fancy "/" (mathmatical symbol))

Installation:
pastebin get 4yBtJdk3 ASCII

Source:
https://pastebin.com/4yBtJdk3

License: MIT



#278228 How to write programs in reasonable time?

Posted by Sewbacca on 04 September 2018 - 09:49 AM in Ask a Pro

Here is my concept:
  • Think about what you will do, untill you have a clear image like BB said.
  • Think about the details. Details is what you program will look like at the end (Let's take an example: GIMP. GIMP isn't just a photo editor. It gives you tools which will make you able to draw and to transform things and filters give the pictures the wanted look.) Try to think out for what purposes your program will be used to. The more you know the details, the more you know what makes your program different from others, the clearer will be your idea and the better the result.
  • Okay, now you know where your program will lead to. Decide now if it is a special purpose or a more general purpose. If it is more general, think of an API (e. g. encryption) otherwise create a program. If you aren't sure if it should be an API then think of a program with a good interface for other programmers like shell does, but you can also use arguments (like git does). Arguments has revolutionised the software industry.
  • Now you have a clear plan what your program (or API) will look like, and how you will access them as a user or a third party programmer. Now happy coding.
Last thing, you should allways start at the beginning. I can't explain it, so here is a example code:

-- Program:
-- Right way:
while true do
  -- start here
end
-- wrong way
local function clalculateSomething()
  x = x + 1
end
-- API
-- Right way
os.loadAPI("api")
-- or
local api = dofile("api.lua")
-- Wrong way
function api1()
  --crazy shit
end

Hope i could help and please exucse my mistakes, if there are, i am not a native speaker.



#278038 Atom text editor clone

Posted by Sewbacca on 08 August 2018 - 05:18 PM in Programs

The program has a quite nice design, but there are some bugs i have noticed:
  • Keywords are highlighted, even if they are a part of a word (for example: color (at the end: or))
  • Comments encapsulated in strings are highlighted (e. g. "--")
  • There is no horizontal scroll
  • you can't open a folder
  • It flickers when there are many changes per second

View PostJummit, on 05 August 2018 - 03:32 PM, said:

pastebin get WeQgf8A7

The download command is not complete: you've forgotten "atom".

Nevertheless, the idea sounds good.



#277693 Artificial Inteligence in ComputerCraft - NeuralNetworks

Posted by Sewbacca on 05 July 2018 - 12:03 PM in APIs and Utilities

I have two questions related to this code:
myNet = AI.Net({2,4, 8, 16,1}) -- What will hapen here and how are the neurons connected?
myNet.feedForward({1,0}) -- Just 1 and zero are allowed values?
myNet.backProp({1})
myNet.getResults()



#277659 load function with table

Posted by Sewbacca on 28 June 2018 - 03:40 PM in Ask a Pro

View PostEveryOS, on 30 May 2018 - 12:32 PM, said:

Your comment made me think of it though, since you pointed out that load can load strings just fine.

Please use it in just this case: You want to change the environment of a function and you don't know the origin of that one.
Because the debug information would get lost, so you won't know in which line an error occur.

Note, string.dump removes all connections to the old environment.
local n = 0
function foo()
  n = n + 1
  return n
end
If you would use this:
load(string.dump(someFunction))
It would throw something like this:
string:-1: attempt to add on nil and number
Please use string.dump only in the case you want to save a anonymous (!) function to a file.



#277658 Negative line number for error debug info

Posted by Sewbacca on 28 June 2018 - 03:26 PM in Ask a Pro

View PostSquidDev, on 31 May 2018 - 05:59 PM, said:

For crying out loud, Minecraft costs the same as 4 cups of coffee or 3 beers.

Erm... Where do you buy your coffee? I mean, where does a cup of coffee cost $6? :lol: