This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Reinified's profile picture

MLG teachers and students table bonanza!

Started by Reinified, 16 June 2017 - 05:37 PM
Reinified #1
Posted 16 June 2017 - 07:37 PM
So I need to find out how to do the following:
1. make a table with all the people in a class. Something like:

tStudentNames = {Andy, Paul, Rob, Jack, Alyssa, Micah, Adam, Pablo}
2. Of those names, I need to select some as "Teachers". Let's say Rob was the teacher.
3. Get a function which takes a name and tells me whether that user is a teacher in true or false.
4. Get a function which lists all teachers.
5. Get a function which lists all students, not teachers
6. Get a function which lists everyone.

This might be a lot to ask, but help is much appreciated!
-Reinified

EDIT:
Scroll to bottom of page, I got it done with the help of
danielsv03

Thanks for the help!
Edited on 17 June 2017 - 04:05 PM
KingofGamesYami #2
Posted 16 June 2017 - 08:04 PM
I see you have posted your homework question on the internet.
1. You're missing quotes from your strings.
2. That's really easy, just make another table and put some of the names in it
3. That's also really easy, just check the table from 2.
4 - 6. Yeah just more really easy table checks.

http://schools.ccsd.net/bonanza/curriculumOverview.pdf#page=6
Edited on 16 June 2017 - 06:09 PM
Reinified #3
Posted 16 June 2017 - 08:16 PM
Lmao no, I live in Finland.
I was intending to use this related to a permissions type system and decided to use a school class as an example because it's used in the documentation.
Bambel Boar #4
Posted 16 June 2017 - 08:18 PM
This looks a lot like a homework question, in what world would someone want to write a program that simply declares who's a teacher and who isn't? I mean come on.

Ditto of what KingofGamesYami said. Smart people don't cheat.

EDIT: The only reason you're not showing the full code is that you're hiding something possibly malicious, according to this forum, apparently. Could you expand on your question?
Edited on 16 June 2017 - 06:20 PM
Reinified #5
Posted 16 June 2017 - 08:46 PM
My full idea is that I could start work on a fork of the chat program, which also includes a special rank or tag for friends. The rank could also recieve access to the /me and /nick commands, which would normally not be given. (On execution of /me the user would I be checked for the required rank. This would be done by checking if that user has a property of "isFriend" or something of that type. Read more about what I mean in properties below. That's why I was asking for the function to find if a user is a "teacher" or in this case a friend.)
I could likely also try to get my head around adding a /listfriends command, which would list all friends.
The task in itself could teach me to add properties to items, like "isOp" or just other properties like names. This could be useful if I wanted to do something like this:
{
Type = "User",
Name = "Reinified",
PermissionLevel = 3,
Tag = "I()I"
}

Hope this widens your view.
supernicejohn #6
Posted 16 June 2017 - 11:29 PM

{
Type = "User",
Name = "Reinified",
PermissionLevel = 3,
Tag = "I()I"
}
You could just nest this into the table you had originally, using the names as keys. There are certainly other ways to do it, but since you've got the two parts, combining them is easy.
tbl = {one = {cool = true, [5] = 6}, going = {onTo = {etc = true}}}
Reinified #7
Posted 17 June 2017 - 06:04 AM
So here's what I've got:

tStudentNames = {
["Alex"] = "Teacher",
["Paul"] = "Student",
["Josh"] = "Student",
["Andy"] = "Teacher"}
sStudentNames = textutils.serialise(tStudentNames)
print(sStudentNames)
And what I need is that it tells me if a person is a "teacher" from a function. LIKE:

nGroup = getGroup( name )
if nGroup > 3 then
print("You"..name "Have a group greater than 3, also known as: "..nGroup"!")

But that's primarily a single true or false property. More could likely be added.

// If someone has figured this out, please explain what the code looks like and how it works. I'm dying to know.
danielsv03 #8
Posted 17 June 2017 - 10:29 AM
What you could do is

local persons = {
	  ["Alex"] = {rank =  "Teacher"; PremissionLevel = 3};
	  ["Paul"] = {rank = "Student"; PremissionLevel = 0};
}

Could be a good table for this
what you could do is that you have an function that checks if student have rank == teacher if so add that person to another table called teachers in a separate file

That could look something like this

teachers = {}
student = {}
function check()
for k,v in pairs(persons) do
if v.rank == "Teacher" then
  table.insert(teachers, k)
elseif v.rank == "Student" then
  table.insert(student, k)
end
end

end

that should separate all the student and teachers into separate tables
then you could just check if that person belongs to that table and add premissions to that table like if the person belongs to teacher table then it has more permissions like permissionslevel 3
Edited on 17 June 2017 - 09:23 AM
Reinified #9
Posted 17 June 2017 - 12:40 PM
Thanks so much! This was a great help, hats off to you sir.
danielsv03 #10
Posted 17 June 2017 - 01:02 PM
Thanks so much! This was a great help, hats off to you sir.

no problem :)/>
Reinified #11
Posted 17 June 2017 - 06:03 PM
Edit:

I just got done with writing a "demo api" for what could be done. It's basically a group manager.
Pastebin link: https://pastebin.com/5tw17Y8U (Download as "UserM")
Pastebin link:https://pastebin.com/XZvWY3Ym (Download as "database")
A quick walkthrough of the functions included:

UserM.list()
Will print all users and their groups.


UserM.getRank(<Name>)
Gets the rank of the inputted user.


UserM.getPermLevel(<Name>)

Gets the permission level of the inputted user.


UserM.setPermLevel(<Name>, <PermLevel>)

Sets the permission level of the target user to the specified value.


UserM.userInfo(<Name>)

Returns the name, rank and permission level of a user.


UserM.setUserName(<OldName>, <NewName>)

Changes the username of the target user to the target value.


UserM.setRank(<Name>, <Rank>)

Set the rank of the target user to the target rank.


UserM.save()
Simple function to save the entered information to the database. Nothing more, nothing less.
Exerro #12
Posted 18 June 2017 - 01:55 PM
It's generally bad to have APIs like this interact with the screen. You'd ideally return a list of users from the `list()` function, and then use `userInfo()` to get more details. Also, is there no `load()` function?