Official Everybody Edits Forums

Do you think I could just leave this part blank and it'd be okay? We're just going to replace the whole thing with a header image anyway, right?

You are not logged in.

#1 Before February 2015

Zumza
Member
From: root
Joined: 2015-02-17
Posts: 4,645

[Question] Access level

In theory I have a User class witch contains: x, y, face, etc.
This User values change... How can i allow access to change them only from my MessageReceivedEventHandler?
Dont put the "Learn to Google" video please. It dosent contain the answer. https://wiki.everybodyedits.com/images/c/c0/069_LOL
Thanks!

Edit:
I have a OOP problem.
I want to change the values from User class only from "OnMessage" function.
eg.:

void OnMessage(object s, Message m) {      if(m.Type=="f")           Users.GetByID(m.GetInt(0)).Face=m.GetInt(1); }

But I shouldn't be able to change that "Face" from any part of the program.

void trool_values() {      Users.GetByID(0).Face=100000000000000; }

I can't hide it because I need to "get" everywhere.
I shouldn't be able to "set" except OnMessage.

The problem is you are able to change the face value outside of onmessage

Last edited by The Doctor (Jan 28 2015 9:41:51 am)


Everybody edits, but some edit more than others

Offline

#2 Before February 2015

Jabatheblob1
Member
Joined: 2015-03-01
Posts: 856

Re: [Question] Access level

Make a bool, set it equal to true at the start of the onMessage(Part with all the if(m.type=="bleh") or with the switch(m) case "bleh":) and at the end of the onMessage, set it to false. And whenever you wanna change a value check to see if the bool is true.... buuuuutttt the only reason really why those values are changing is because it happened in the world so a message would get sent... so i don't believe i am understanding your question.

Are you talking about only when yours goes off(msesages that is, when you send a message through the world)? which i still don't think is correct.


If you would like me to make a bot for you, go here.

Offline

#3 Before February 2015

Buzzerbee
Forum Admin
From: Texas, U.S.A.
Joined: 2015-02-15
Posts: 4,571

Re: [Question] Access level

I don't quite understand.

You could make a Dictionary<int, User> int being the user ID and User being your User class

Then you'd do something like userDictionar[5].Face = message.GetInt(1) or whatever the face ID message is for "f"

This being pseudo code as I'm on my phone and it's hard to type


TdQRyz3.png
https://wiki.everybodyedits.com/images/5/5d/135_bee

Offline

#4 Before February 2015

Zumza
Member
From: root
Joined: 2015-02-17
Posts: 4,645

Re: [Question] Access level

Im sorry for my english
I have a OOP problem.
I want to change the values from User class only from "OnMessage" function.
eg.:

void OnMessage(object s, Message m) {      if(m.Type=="f")           Users.GetByID(m.GetInt(0)).Face=m.GetInt(1); }

But I shouldn't be able to change that "Face" from any part of the program.

void trool_values() {      Users.GetByID(0).Face=100000000000000; }

I can't hide it because I need to "get" everywhere.
I shouldn't be able to "set" except OnMessage.

Last edited by The Doctor (Jan 28 2015 6:47:00 am)


Everybody edits, but some edit more than others

Offline

#5 Before February 2015

Buzzerbee
Forum Admin
From: Texas, U.S.A.
Joined: 2015-02-15
Posts: 4,571

Re: [Question] Access level

Uhh why would you want to do that?


TdQRyz3.png
https://wiki.everybodyedits.com/images/5/5d/135_bee

Offline

#6 Before February 2015

TiKen
Member
Joined: 2015-02-24
Posts: 298

Re: [Question] Access level

Well, you set "set" as private, and do a method in the class user to change that value, with for example some protection which suit your needs.

Tadam ! OOP 101

Offline

#7 Before February 2015

Zumza
Member
From: root
Joined: 2015-02-17
Posts: 4,645

Re: [Question] Access level

Well if I add a method, any function can change it by calling the method... Or am Im missing something?


Everybody edits, but some edit more than others

Offline

#8 Before February 2015

SmittyW
Member
Joined: 2015-03-13
Posts: 2,085

Re: [Question] Access level

I still don't understand the question. Are you saying that the problem is you are able to change the face value outside of onmessage? Is something else triggering it by accident or are you telling us that you don't want it to change even though you are intentionally doing so?

Offline

#9 Before February 2015

Zumza
Member
From: root
Joined: 2015-02-17
Posts: 4,645

Re: [Question] Access level

SmittyW. wrote:

I still don't understand the question. Are you saying that the problem is you are able to change the face value outside of onmessage? Is something else triggering it by accident or are you telling us that you don't want it to change even though you are intentionally doing so?

I don't want it to change even though I am intentionally doing so.

Last edited by The Doctor (Jan 28 2015 9:48:45 am)


Everybody edits, but some edit more than others

Offline

#10 Before February 2015

SmittyW
Member
Joined: 2015-03-13
Posts: 2,085

Re: [Question] Access level

The Doctor wrote:
SmittyW. wrote:

I still don't understand the question. Are you saying that the problem is you are able to change the face value outside of onmessage? Is something else triggering it by accident or are you telling us that you don't want it to change even though you are intentionally doing so?

I don't want it to change even though I am intentionally doing so.

So stop changing it?

Offline

#11 Before February 2015

Jabatheblob1
Member
Joined: 2015-03-01
Posts: 856

Re: [Question] Access level

the only reason to change the values is if onmessage says the value has changed so you would only change the value in onmessage anyways.


If you would like me to make a bot for you, go here.

Offline

#12 Before February 2015

Zumza
Member
From: root
Joined: 2015-02-17
Posts: 4,645

Re: [Question] Access level

If somebody not me, wants to make my bot unfunnctional will be able with changing this values.


Everybody edits, but some edit more than others

Offline

#13 Before February 2015

Buzzerbee
Forum Admin
From: Texas, U.S.A.
Joined: 2015-02-15
Posts: 4,571

Re: [Question] Access level

If you give someone the source code regardless they can do whatever they want...


TdQRyz3.png
https://wiki.everybodyedits.com/images/5/5d/135_bee

Offline

#14 Before February 2015

Zumza
Member
From: root
Joined: 2015-02-17
Posts: 4,645

Re: [Question] Access level

So no solution?


Everybody edits, but some edit more than others

Offline

#15 Before February 2015

ewoke
Member
Joined: 2015-02-20
Posts: 412

Re: [Question] Access level

your question doesnt make any sense. if you dont want people to edit your code dont share your code,
if you dont want the user to be edited outside the message handler simply dont edit it outside the message handler


if you can read this....good for you

Offline

#16 Before February 2015

Jabatheblob1
Member
Joined: 2015-03-01
Posts: 856

Re: [Question] Access level

unless this bot could possibly cause problems with ee such as a world crashing system then don't share it. If it's a bot that can cause problems if edited, don't share it. if it's just a cool fun bot that could be messed up if someone edited it, that just ruins their experience so it doesn't matter. So there's no problem really unless you share it.


If you would like me to make a bot for you, go here.

Offline

#17 Before February 2015

hummerz5
Member
From: wait I'm not a secret mod huh
Joined: 2015-08-10
Posts: 5,852

Re: [Question] Access level

The problem also expands into a different... thinking.
How are you taking someone else's code into your program? Is that such a great idea? Is this a framework?

There are ways to run "plugins" and manage what these plugins have access to... perhaps look there

Or just let the thread die. //forums.everybodyedits.com/img/smilies/smile

Offline

#18 Before February 2015

Zumza
Member
From: root
Joined: 2015-02-17
Posts: 4,645

Re: [Question] Access level

yes is a framework for plugins
you got a solution?
the plugin access my user class by an interface so do I access the plugin

Last edited by The Doctor (Feb 4 2015 2:03:58 pm)


Everybody edits, but some edit more than others

Offline

#19 Before February 2015

Zumza
Member
From: root
Joined: 2015-02-17
Posts: 4,645

Re: [Question] Access level

How stupid I am? The answer is obvious I make User as interface.
Lock and a warning for my attention please I deserve that...


Everybody edits, but some edit more than others

Offline

#20 Before February 2015

XxAtillaxX
Member
Joined: 2015-11-28
Posts: 4,202

Re: [Question] Access level

Locked on request of OP.


signature.png
*u stinky*

Offline

#21 2015-02-20 09:17:04

realmaster42
Formerly marcoantonimsantos
From: ̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍
Joined: 2015-02-20
Posts: 1,380
Website

Re: [Question] Access level

Well you have a really little problem right there.

"f" message requires worldKey, so go get a Derot if you don't have it and store it's value on variables in "init"

Since you don't use a case switch, you must change your if statement to:

if (m.Type == worldKey + "f") then

That detects the code, and works. (Well for me it does. . .)


http://i.imgur.com/bjvgH5L.png?1

Offline

#22 2015-02-20 11:08:42

EuadeLuxe
Member
Joined: 2015-02-18
Posts: 12

Re: [Question] Access level

Well, um, what about restructuring your code a little bit here? I assume you've got that class called user in some kind of namespace. So you've got exactly two options to overcome your problem:

  1. You make all fields inside your user class private and have the message handler be a function inside your class so that it will have access to the classes private fields directly. For users of your class you may then simply provide read-only properties. You might even want to consider a manager class for your user's which maps each user object on its unique id.

  2. Or you might want to have that manager class to have access to the user object's fields by making all the fields package-intern (I don't remember how it is called in C#) and putting the manager class inside the very same namespace. You then need only one message handler inside the manager class which will look for the appropriate user object whenever a message is received and then updates its fields properly.

In fact, I suppose this is what @tikenalpha proposed as well.


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512

C++, C#, Java, PHP, JavaScript and Python programmer
Enjoys developing all day
Don't believe it? Then verify me here, https://keybase.io/verify, and here: https://www.gommehd.net/members/blackypaw.32820/ (open the Informations tab and you'll find another PGP signature)
-----BEGIN PGP SIGNATURE-----
Version: Keybase OpenPGP v2.0.46
Comment: https://keybase.io/crypto

wsBcBAABCgAGBQJWCo8vAAoJEG4qS86NYi+iL1kH/Aq8bRm7tjZAqeBE4YBR0bJx
ao40xBbFsQ1KjZUnUgQosFP66H0JqlGmrJnyseyBLM+xccrkXapXN/T6csKTTzMy
dFV6i55+Jn/r1Y45+7yZHSYYZeG+OsFRin+Yvj0R69U6fuGLzDhfd9DFFlj0ORUw
qScy5/A0v+F9mLi+4a/fp9io4oF2kHiqzFNGCy4TueKgU5N+Um8UvhkNonLvRyvD
kOpjym8co4VLEDLfTVJgQAUhmmwW1NHvyaDDj9hjW4ERmhuX7ITwtrVdyAG6VhJB
DEN9SjkSTbGnvWepCv2xnqKmvXwyCXrds4d6Tt/wOz+794Optk8paYT/IO2RM2w=
=nW2J
-----END PGP SIGNATURE-----

Offline

#23 2015-02-21 21:34:55

capasha
Member
Joined: 2015-02-21
Posts: 4,066

Re: [Question] Access level

marcoantonimsantos wrote:

Well you have a really little problem right there.

"f" message requires worldKey, so go get a Derot if you don't have it and store it's value on variables in "init"

Since you don't use a case switch, you must change your if statement to:

if (m.Type == worldKey + "f") then

That detects the code, and works. (Well for me it does. . .)

You don't know what you are doing. You don't need worldkey there.

Offline

#24 2015-02-22 08:51:05, last edited by Zumza (2015-02-22 08:51:25)

Zumza
Member
From: root
Joined: 2015-02-17
Posts: 4,645

Re: [Question] Access level

XxAtillaxX wrote:

Locked on request of OP.

I fixed the problem along time ago and this should be locked.


Everybody edits, but some edit more than others

Offline

Zumza1424591465475625

Board footer

Powered by FluxBB

[ Started around 1715028901.8592 - Generated in 0.203 seconds, 10 queries executed - Memory usage: 1.69 MiB (Peak: 1.93 MiB) ]