Jump to content


TechnicalCoding's Content

There have been 32 items by TechnicalCoding (Search limited from 30-March 23)


By content type

See this member's


Sort by                Order  

#264433 ComputerCraft did a miss

Posted by TechnicalCoding on 04 February 2017 - 11:01 AM in Ask a Pro

View PostBomb Bloke, on 04 February 2017 - 01:02 AM, said:

Presumably when you're calling your example function, "var" is a string. That's the only situation in which the code snippet you've got there would act as you're expecting.

But "not type(whatever)" will always be a boolean, which will never be equal to "string".

That is to say,

not type(var) == "string"

... is the same as:

(not type(var)) == "string"

... which is different to:

not (type(var) == "string")

... which is the same as:

type(var) ~= "string"

Thanks for the explanation, helps a lot!



#264396 ComputerCraft did a miss

Posted by TechnicalCoding on 04 February 2017 - 12:43 AM in Ask a Pro

View PostDog, on 03 February 2017 - 10:56 PM, said:

Since true or false will never equal "table" you won't get the results you expect.

Why does it work using

function example ( var )
  if not type ( var ) == 'string' then
    print ( 'Error: Expected string!' )
  end
end



#264392 ComputerCraft did a miss

Posted by TechnicalCoding on 03 February 2017 - 11:06 PM in Ask a Pro

View PostDog, on 03 February 2017 - 10:56 PM, said:

Instead of using "not"
if not type(something) == "something" then
But why does the above code not work? What is wrong with it? And what makes the below code work? What's right with it?

View PostDog, on 03 February 2017 - 10:56 PM, said:

use "doesn't equal" instead
if type(something) ~= "something" then



#264390 ComputerCraft did a miss

Posted by TechnicalCoding on 03 February 2017 - 10:38 PM in Ask a Pro

I have this function for my operative system which will create a button, which is something I asked for some details about in my last post. But in my function I have kind of a "self" object, which the function will return all the values to.

oos.graphic.btn = function ( obj, string, settings )
  if not type ( obj ) == 'table' then -- This is where it misses, because at the bottom you'll see that I put in a string, but for me it fails to see that obj is not a table.
	oos.functions.throw ( ERROR, 'SELF expects a table, not' .. type ( obj ) );
	return false;
  end
end

-- ( OpenOS: Debug ) --
oos.graphic.btn ( 'This is not a table', 'Button Content', { ["width"] = 16, ["height"] = 3, ["offsetY"] = 1, ["offsetX"] = 1, ["foregroundColor"] = colors.white, ["backgroundColor"] = colors.red } );

Does anyone else have this problem?

It is not anything wrong with the "oos.functions.throw" function, but anyway, this is how it works:

oos.functions.throw = function ( Type, message )
  local ocolor = oos.term.getTextColor (  );
  local obgcolor = oos.term.getTextColor (  );

  if not type ( Type ) == "string" then
	oos.term.setTextColor ( oos.settings.types [ ERROR ].bg );
	oos.term.setBackgroundColor ( oos.settings.types [ ERROR ].color );
	write ( oos.settings.types [ ERROR ].title );

	oos.term.setTextColor ( oos.settings.types [ ERROR ].color );
	oos.term.setBackgroundColor ( oos.settings.types [ ERROR ].bg );
	write ( ' ' .. 'Expected TYPE at oos.functions.throw ( TYPE, message )' );

	oos.term.setTextColor ( ocolor );
	oos.term.setBackgroundColor ( obgcolor );
	print ( '' );

	return false;
  end

  if oos.settings.types [ Type ] == nil then
	Type = 'UNKNOWNException';
  end

  oos.term.setTextColor ( oos.settings.types [ Type ].bg );
  oos.term.setBackgroundColor ( oos.settings.types [ Type ].color );
  write ( oos.settings.types [ Type ].title );

  oos.term.setTextColor ( oos.settings.types [ Type ].color );
  oos.term.setBackgroundColor ( oos.settings.types [ Type ].bg );
  write ( ' ' .. message );

  oos.term.setTextColor ( ocolor );
  oos.term.setBackgroundColor ( obgcolor );
  print ( '' ); -- New Line

  return true;
end

These variables below is being implemented at the the very top of my os:
ERROR = 'ERRORException';
WARNING = 'WARNINGException';
SUCCESS = 'SUCCESSException';
INFO = 'INFOException';
USAGE = 'USAGEException';

set = 'SET';
get = 'GET';
current = 'CURRENT';

So what makes my oos.graphic.btn function fail?

The table which contains the different exceptions in the throw function
-- ( OpenOS: Exception delarations ) --
oos.settings.types = {
  ['ERRORException']   = {
    color = c.red,
    bg = c.black,
    title = 'Error'
  },

  ['WARNINGException'] = {
    color = c.yellow,
    bg = c.black,
    title = 'Warning'
  },

  ['SUCCESSException'] = {
    color = c.green,
    bg = c.black,
    title = 'Success'
  },

  ['INFOException']    = {
    color = c.blue,
    bg = c.black,
    title = 'Info'
  },

  ['USAGEException']   = {
    color = c.cyan,
    bg = c.black,
    title = 'Usage'
  },

  ['UNKNOWNException'] = {
    color = c.gray,
    bg = c.black,
    title = 'Unknown'
  }
};



#264389 OOP objects in LUA

Posted by TechnicalCoding on 03 February 2017 - 10:17 PM in Ask a Pro

View PostKouksi44, on 03 February 2017 - 03:08 PM, said:

The best way of implementing classes and objects is probably through Lua's metatable feature. This especially comes in handy if you want your classes to inherit from other classes.

*shameless self promotion*

I wrote a library that should have everything you showed in your example, defining classes, making members public/private etc.
You might want to check it out if you are interested in how it works.

Interesting, where can I have a look?



#264345 OOP objects in LUA

Posted by TechnicalCoding on 02 February 2017 - 10:51 PM in Ask a Pro

I am currently working on a operative system in LUA which is for computercraft, and I wanted to create a clickable GUI where I will want a function to create a button, but I god some issues using function cause I'd have to specify everything myself, so I wanted to create an Advanced OOP class.

For example in PHP I'd do
<?php
class button
{
  public clickEvent;
  public posX;
  public posY;
  private removeEvent;

  public function __contruct ( x, y, text, fg, bg ) {
    /* Code here */
  }

  /* ETC */

  public function clicked(...){...}
  public function removed(...){...}
}

$btn = [];
$btn[] = new button ( 1, 1, 'Hello world', colors.blue, colors.white );
?>


But how would I do this in LUA without having tons of functions that requires to do functonname (table, btn, parameters

Thanks in advance!



#264342 Hacking an OS

Posted by TechnicalCoding on 02 February 2017 - 10:14 PM in Ask a Pro

The hard solution is to create your own IDE which would check if there is any errors with the LUA code that the user creates and print them out, this prevents that the user can "Crash" the OS, then also create a folder for every user that the user is limited to. for example 'users/Username/scripts' and inside this scripts folder the user can create folders and edit files, but are limited to go out of that folder.

I am currently working on an Advanced operating system and I would happily be doing a collab with you!

I am also very experienced in web languages and will create a appstore for my OS, also I will use online login forms and register forms so the user can connect to the forums and socket servers. And include graphical content such as a draw function to create boxes,

another of my current project is similar to cshtml or asp.net, basically create luahtml, so basically you will be able to use html, and create script tags where lua code will be executed. And a lot of custom events and clickable guis, etc.

Please add me on skype: technicalcoding
if you want to collaborate with me :)



#257046 Check if string is in Table without giving the string a condition in table

Posted by TechnicalCoding on 29 July 2016 - 12:48 AM in Ask a Pro

How may i get the string position in the username table and then use it to get the string of first_name in the same position?



#257044 Check if string is in Table without giving the string a condition in table

Posted by TechnicalCoding on 29 July 2016 - 12:22 AM in Ask a Pro

View Postvalithor, on 29 July 2016 - 12:07 AM, said:

You would need to manually loop through the table and see if the string is in there by comparing each entry to the string you are looking for.

example function:

function check(tbl,str)
  for k,v in ipairs(tbl) do
	if v == str then
	  return true
	end
  end
  return false
end

Example usage:

if check(tableToCheck,StringToCheckFor)

I have tried both with speech marks and without, Everything it returns on if statements is this:


startup:107: attempt to index ? (nil value)
line 107
if check(sql["oss"]["users"]["username"], username_input) == true then

View Postvalithor, on 29 July 2016 - 12:07 AM, said:

You would need to manually loop through the table and see if the string is in there by comparing each entry to the string you are looking for.

example function:

function check(tbl,str)
  for k,v in ipairs(tbl) do
	if v == str then
	  return true
	end
  end
  return false
end

Example usage:

if check(tableToCheck,StringToCheckFor)

I have tried both with speech marks and without, Everything it returns on if statements is this:


startup:107: attempt to index ? (nil value)
line 107
if check(sql["oss"]["users"]["username"], username_input) == true then



#257041 Check if string is in Table without giving the string a condition in table

Posted by TechnicalCoding on 29 July 2016 - 12:15 AM in Ask a Pro

View Postvalithor, on 29 July 2016 - 12:13 AM, said:

View PostTechnicalCoding, on 29 July 2016 - 12:10 AM, said:

How would I check the username table which is in the last layer of the SQL table?

check(sql["oss"]["Users"]["username"],username_input)
Will they be en Speech marks even though in the table teir not?



#257039 Check if string is in Table without giving the string a condition in table

Posted by TechnicalCoding on 29 July 2016 - 12:10 AM in Ask a Pro

View Postvalithor, on 29 July 2016 - 12:07 AM, said:

You would need to manually loop through the table and see if the string is in there by comparing each entry to the string you are looking for.

example function:

function check(tbl,str)
  for k,v in ipairs(tbl) do
	if v == str then
	  return true
	end
  end
  return false
end

Example usage:

if check(tableToCheck,StringToCheckFor)
How would I check the username table which is in the last layer of the SQL table?



#257037 Check if string is in Table without giving the string a condition in table

Posted by TechnicalCoding on 29 July 2016 - 12:01 AM in Ask a Pro

I am working on a in game SQL Server for CC, but I need to be able to check if a string is in a table without using conditions like "root"=true, "user1"=true

This is my current table I want to check,
local sql = {
oss = {
  Users = {
   id = {
	0
   },
   username = {
	"root"
   },
   password = {
	""
   },
   first_name = {
	"Root"
   },
   last_name = {
	"User"
   },
   active = {
	1
   }
  }
}
}
I've also got the read function for username which is named: username_input

If sql[oss][users][username][username_input] (And String exists code)

how may i do that? please help!



#255069 read() add string into read before writing

Posted by TechnicalCoding on 29 June 2016 - 02:48 AM in Ask a Pro

View PostKingofGamesYami, on 29 June 2016 - 01:02 AM, said:

So basically like a text field that has a description in it before you start typing? It's not exactly easy, but you *can* do it.

Not exactly an description, but I want it to contain itself, basicly I am using a while loop to make it go over and over again, and for each time it has to repeat I want it to contain the string it had before the it kind of overlap itself, so basicly just using itself (or duplicate it) to make it just contain itself again..



#255065 read() add string into read before writing

Posted by TechnicalCoding on 29 June 2016 - 12:43 AM in Ask a Pro

I am creating something to an operating system, I also want some kind of "memory" to it, and thats good, but what I am having problems to understand is how I can assign text/string to read() before anyone starts writing to it?

EXAMPLE
---------------------------
I have an username variable which use read, they get 3 attempts trying to figure out right details but I want that after first attempt I want the same username to appear to second so no one needs to rewrite the username.


Any ideas? Thanks



#254845 Converting KEYCODE into CHARACTER

Posted by TechnicalCoding on 26 June 2016 - 01:29 PM in Ask a Pro

View PostMKlegoman357, on 22 June 2016 - 09:09 PM, said:

View PostTechnicalCoding, on 22 June 2016 - 06:54 PM, said:

View PostLyqyd, on 22 June 2016 - 04:55 PM, said:

You could not use a filter when pulling events, allowing you to handle both char events for typed characters and key events for control keys. This is what the read function does.
I have tested this and it works perfectly... It gets the pressed key id/code and it finds the name of it..

But this will not detect whether the letter written should be upper case or not (by holding shift button or caps lock). Also, numbers won't work. And if someone will be using a keyboard with a different layout then they won't be able to write anything. You should simply remove the event filter and use both: "key" and "char" events. Using the "key" event for backspace and enter and "char" event for any text characters. Oh, and there's also the "paste" event which you could add support for.
True, but it is good enough for my use, I have also been adding support for the paste event :)



#254531 Converting KEYCODE into CHARACTER

Posted by TechnicalCoding on 22 June 2016 - 06:54 PM in Ask a Pro

View PostLyqyd, on 22 June 2016 - 04:55 PM, said:

You could not use a filter when pulling events, allowing you to handle both char events for typed characters and key events for control keys. This is what the read function does.
I have tested this and it works perfectly... It gets the pressed key id/code and it finds the name of it..



#254519 Converting KEYCODE into CHARACTER

Posted by TechnicalCoding on 22 June 2016 - 04:50 PM in Ask a Pro

Answer found!
By adding this line after local e,key = os.pullEvent("key")
local k = keys.getName(key)
then use "k" instead of key

which now means i can do
if k=="character" THEN



#254516 Converting KEYCODE into CHARACTER

Posted by TechnicalCoding on 22 June 2016 - 04:39 PM in Ask a Pro

View PostIncinirate, on 22 June 2016 - 04:32 PM, said:

View PostTechnicalCoding, on 22 June 2016 - 04:20 PM, said:

View PostXelostar, on 22 June 2016 - 04:15 PM, said:

You can use

if key == keys.enter then
  ...
elseif key == keys.backspace then
  ...
end

or something like that.

This do not work.. ;( sadly

View PostXelostar, on 22 June 2016 - 04:15 PM, said:

You can use

if key == keys.enter then
  ...
elseif key == keys.backspace then
  ...
end

or something like that.

I know how I could use read() function, but that would be too much code in one single line + a mess!

Also just FYI you could just use only key events by creating a reverse lookup table, it's actually very simple:

local lookup = {}
for k,v in pairs(keys) do
	lookup[v] = k
end

That way you can just do this:
e,key = os.pullEvent("key")
local char = lookup[key]
if char=="g" then --do stuff
elseif char=="backspace" then --do other stuff
end
Doing this made it output : nil, now what?



#254514 Converting KEYCODE into CHARACTER

Posted by TechnicalCoding on 22 June 2016 - 04:28 PM in Ask a Pro

I have been looking into the read function, so what it tells me is that it is not possible to use read() and do live output if ex Username avaible, Username Taken, etc, cause everything assigned to it is self assigning...



#254513 Converting KEYCODE into CHARACTER

Posted by TechnicalCoding on 22 June 2016 - 04:20 PM in Ask a Pro

View PostXelostar, on 22 June 2016 - 04:15 PM, said:

You can use

if key == keys.enter then
  ...
elseif key == keys.backspace then
  ...
end

or something like that.

This do not work.. ;( sadly

View PostXelostar, on 22 June 2016 - 04:15 PM, said:

You can use

if key == keys.enter then
  ...
elseif key == keys.backspace then
  ...
end

or something like that.

I know how I could use read() function, but that would be too much code in one single line + a mess!



#254510 Converting KEYCODE into CHARACTER

Posted by TechnicalCoding on 22 June 2016 - 04:07 PM in Ask a Pro

View PostNanoBob, on 22 June 2016 - 04:05 PM, said:

View PostTechnicalCoding, on 22 June 2016 - 04:03 PM, said:

Might be smart, but to notice the ENTER & BACKSPACE click what will the name be?
You could use both events in that case. But instead couldn't you simply use the read() function?
No, this is some kind of read() function but my custom one, which allows me to give live replies to the user ex "Username is already in use" so they do not need to re enter the whole string. Also what is the names of enter and backspace?



#254508 Converting KEYCODE into CHARACTER

Posted by TechnicalCoding on 22 June 2016 - 04:03 PM in Ask a Pro

Might be smart, but to notice the ENTER & BACKSPACE click what will the name be?



#254506 Converting KEYCODE into CHARACTER

Posted by TechnicalCoding on 22 June 2016 - 03:51 PM in Ask a Pro

Currently I have script which looks like this:

NOTE: I have made these variables shortened from term
c = term.setTextColor
b = term.setBackgroundColor
cp = term.setCursorPos
z = colors

while true do
			local event, key = os.pullEvent("key")
			if key == 28 then break elseif key == 14 then
				
				local xpos1, ypos1 = term.getCursorPos()
				
				if xpos1 > x then
				
					cp(xpos1 - 1, ypos1)
					b(z.black)
					write(" ")
					cp(xpos1 - 1, ypos1)
				end
			else
				write(tostring(key)) --- I want this to output the character that belongs to the keycode entered, this do only output the keycode
			end
		end

View PostTechnicalCoding, on 22 June 2016 - 04:50 PM, said:

Answer found!
By adding this line after local e,key = os.pullEvent("key")
local k = keys.getName(key)
then use "k" instead of key

which now means i can do
if k=="character" THEN

That is how i fixed the problem! Hope everyone can get a use of it! :)



#254471 Need ideas for operating system

Posted by TechnicalCoding on 22 June 2016 - 01:13 AM in Programs

 KingofGamesYami, on 22 June 2016 - 01:11 AM, said:

Github integration. I would actually use an OS that would allow me to commit and/or clone to my repositories.
Good idea! I'll do that, but there might be security leaks with this also, but I will try to use encryptions and security levels to figure this out..



#254469 Need ideas for operating system

Posted by TechnicalCoding on 22 June 2016 - 12:58 AM in Programs

Currently I have been working with an operating system, I have added 3dprinting, custom chat, login, register, logout, firewalls, download folder for each user etc, timer, clock in gui, custom script editor for "NEW" lua extension, new user, delete user, lock user, lock screen, disable account, permissions for users, gui, command line, advanced command line, security bridge between users, security.

Some ideas to more stuff to add in? I really need more ideas..

EDIT: I also have encryption for passwords.
EDIT2: Current ideas: webserver, webbrowser, webChat, web code extension, new gui, download from other pages than pastebin, download zip files and extract them, also upload folders to server with ftp connection (will be uploaded to my website

UPDATES
GitHub project - will require logging in to git hub from CC, there might be a secure way to do this in as creating assignment file and deleting it afterwards when process is done!