Using code from tutorials and plagarism
Using code from tutorials and plagarism
I have a question regarding usage of code in from online tutorials. I'm currently working on my a masters thesis project and I'm learning to use Unity for it. I've looked up forum how-tos online and from tutorials on how to do certain things in the engine using C#. I've modified the code a bit for my own uses, but most of it is the same (the basic structure is identical). Is it considered plagiarizing if I used the code in the final product (with citations) and then use that product for future education purposes? I'm not familiar with what is and is not considered plagiarizing when it comes to computer code, since its a functional product.
Re: Using code from tutorials and plagarism
Fair use is intentionally a bit broader when it comes to educational purposes - and that includes a masters thesis. As long as you cite your sources you should be okay.
Just don't base the entire thing on one tutorial, or make it all nothing but tutorial code. Make it your own.
Just don't base the entire thing on one tutorial, or make it all nothing but tutorial code. Make it your own.
- nazakomu
- Posts: 131
- Joined: Wed Nov 30, 2016 12:51 am
- Graphics Processor: nVidia with Vulkan support
Re: Using code from tutorials and plagarism
Agreed 100 percent! It's okay to be doing it at first but you'll almost never get anywhere if you don't spend time and dedication on doing your own code and finding your own method of doing things in coding.Rachael wrote:Just don't base the entire thing on one tutorial, or make it all nothing but tutorial code. Make it your own.
I can admittedly already say the same thing for something like ZScript, where I spent my first month and a half looking at others' code and trying to always make something similar and eventually I got the hang of it enough to make my own without any inspection on others' code.

Re: Using code from tutorials and plagarism
I'll have to get a firmer grasp of C#'s syntax before coding my own stuff. I'm currently not even sure how to look up help because I don't know the proper terminology to search for. For example, what does it mean when you have "something.something-else"? (i.e. Time.deltatime) What does the period between the two words denote? I know what its doing. I just don't know if that's just the coders' choice of aesthetic, or it actually has significance.
For example, the following:
I know the code is using a raycast from the viewing camera pointing at the mouse position on the screen and its saving that as the Raycast variable "hit", and using that to deform the mesh according to the force and the forceOffset set by the user. But my understanding of the code stops at the if statement. I have no idea what "if (Physics.Raycast(inputRay, out hit))" means. Im used to comparison operations such as <,>, <=, etc. Not what I'm seeing here.
For example, the following:
Code: Select all
void HandleInput ()
{
Ray inputRay = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast(inputRay, out hit))
{
MeshDeformer deformer = hit.collider.GetComponent<MeshDeformer>();
if (deformer)
{
Vector3 point = hit.point;
point += hit.normal * forceOffset;
deformer.AddDeformingForce(point, force);
}
}
}
Re: Using code from tutorials and plagarism
The period denotes "member" - basically the syntax is Class.member. Member can either be a function or a variable or a pointer (well, in C++, anyway, not sure about C#).
So saying hit.point is basically calling the class "hit" which is one of the classes that will be leaving the function as a return value - and ".point" is asking exactly where did this hit occur.
Likewise, deformer.AddDeformingForce is calling the class member function AddDeformingForce of the class "deformer".
The easiest way to figure out what class has what functions (aka methods) or variables is to look up the class definition, itself.
So saying hit.point is basically calling the class "hit" which is one of the classes that will be leaving the function as a return value - and ".point" is asking exactly where did this hit occur.
Likewise, deformer.AddDeformingForce is calling the class member function AddDeformingForce of the class "deformer".
The easiest way to figure out what class has what functions (aka methods) or variables is to look up the class definition, itself.
- phantombeta
- Posts: 2184
- Joined: Thu May 02, 2013 1:27 am
- Operating System Version (Optional): Windows 10
- Graphics Processor: nVidia with Vulkan support
- Location: Brazil
Re: Using code from tutorials and plagarism
@Amuscaria
1) That period between two words is the member-access operator. "foo.bar" accesses the "bar" member of the class or struct "foo".
2) See that "out" before the "hit" argument there? That means that argument is actually used for output, not input. The function probably returns a bool so you can use it like this, while giving you the actual output of the function via an out argument.
As for why there's no comparison operator in there, comparison operators do a comparison between two arguments, and if the arguments pass the comparison, they return true. If not, they return false. All "if" does is check if a bool is true and execute the code in the following block if it is.
Some variable types also usually automatically convert to bool when used where a bool is required/requested.
I recommend reading some general C# books. The C# Yellow Book seems pretty good.
I didn't read said book when learning C#, but after coming back to it from D (which is more flexible and powerful, while being somewhat easier to use than C#, IMO), I had to look some stuff up, and I read that book for figuring out how to do some things I needed to do.
You can get it here.
@Rachael
It can indeed be any of those, although pointers are not used very often in C#* AFAIK.
* You actually have to enable the "unsafe" context in the compilation options to even be able to use them, and you have to put them inside an "unsafe" block. Using said "unsafe" block also disables things like array index range-checking, IIRC.
1) That period between two words is the member-access operator. "foo.bar" accesses the "bar" member of the class or struct "foo".
2) See that "out" before the "hit" argument there? That means that argument is actually used for output, not input. The function probably returns a bool so you can use it like this, while giving you the actual output of the function via an out argument.
As for why there's no comparison operator in there, comparison operators do a comparison between two arguments, and if the arguments pass the comparison, they return true. If not, they return false. All "if" does is check if a bool is true and execute the code in the following block if it is.
Some variable types also usually automatically convert to bool when used where a bool is required/requested.
I recommend reading some general C# books. The C# Yellow Book seems pretty good.
I didn't read said book when learning C#, but after coming back to it from D (which is more flexible and powerful, while being somewhat easier to use than C#, IMO), I had to look some stuff up, and I read that book for figuring out how to do some things I needed to do.
You can get it here.
@Rachael
It can indeed be any of those, although pointers are not used very often in C#* AFAIK.
* You actually have to enable the "unsafe" context in the compilation options to even be able to use them, and you have to put them inside an "unsafe" block. Using said "unsafe" block also disables things like array index range-checking, IIRC.
Re: Using code from tutorials and plagarism
Ah, Ok.
Haven't look into C# that much yet. Watched a couple of "crash course" tutorials on YT so far. Started a couple of weeks ago because I wanted/needed Unity to make some ultrasound simulator for education purposes in the hospital. I've only taken 1 semester of CS101 C++ years ago to fill an Engineering requirement, so we haven't gotten into members or classes yet (at least not in depth). Think the farthest we go was pointers, and barely even that.
I'll take a look at the books recommended. Thanks!
Haven't look into C# that much yet. Watched a couple of "crash course" tutorials on YT so far. Started a couple of weeks ago because I wanted/needed Unity to make some ultrasound simulator for education purposes in the hospital. I've only taken 1 semester of CS101 C++ years ago to fill an Engineering requirement, so we haven't gotten into members or classes yet (at least not in depth). Think the farthest we go was pointers, and barely even that.
I'll take a look at the books recommended. Thanks!

- NeuralStunner
-
- Posts: 12328
- Joined: Tue Jul 21, 2009 12:04 pm
- Preferred Pronouns: No Preference
- Operating System Version (Optional): Windows 11
- Graphics Processor: nVidia with Vulkan support
- Location: capital N, capital S, no space
- Contact:
Re: Using code from tutorials and plagarism
For a current project, I wasn't going to be able to use a segment of bugfix code provided by someone else (due to their use restrictions). However, by understanding the bug I was able to write my own fix implementation. (It still seemed polite to credit those authors for identifying the problem.)
Re: Using code from tutorials and plagarism
here's the modified code from yesterday for context:
What does the stuff in the "out" mean in the following example:
I THINK it's setting the 1st and 2nd parameters for Physics.Raycast to the vector3 values of "InputRay" and "hit", respectively. I'm not sure what the "out" does, though.
I also don't know what the <> backets mean in the following (heck, I don't know what that entire line means):
Spoiler:More syntax questions.
What does the stuff in the "out" mean in the following example:
Code: Select all
if (Physics.Raycast(inputRay, out hit)
I also don't know what the <> backets mean in the following (heck, I don't know what that entire line means):
Code: Select all
MeshDeformer deformer = hit.collider.GetComponent<MeshDeformer>()
Re: Using code from tutorials and plagarism
"Out" simply means that you are expected to pass a variable into the function and the function is allowed to modify it and send it back (sort of as a poor-man's "extra return value"). This seems to be something specific to C# - C/C++ does this by simply using pointers. The calling function is then able to make use of the modified variable - i.e. if a function is defined as something(out a) and "a" changes to 4 inside the function, then calling something(i) causes i to become 4 in the parent function.
As for the <>'s I know that in C++ they are for specific types of type-casts. I would assume that is the case here, as well - it is forcing the return value or variable to be a certain type, regardless of the type it may have previously been. Sometimes this is an actually functional cast - but other times it is used simply for syntax enforcement in order to help reduce the amount of errors in the code.
As for the <>'s I know that in C++ they are for specific types of type-casts. I would assume that is the case here, as well - it is forcing the return value or variable to be a certain type, regardless of the type it may have previously been. Sometimes this is an actually functional cast - but other times it is used simply for syntax enforcement in order to help reduce the amount of errors in the code.
- phantombeta
- Posts: 2184
- Joined: Thu May 02, 2013 1:27 am
- Operating System Version (Optional): Windows 10
- Graphics Processor: nVidia with Vulkan support
- Location: Brazil
Re: Using code from tutorials and plagarism
"out" is the keyword for output arguments.
"hit" there is still being used for outputting the function's actual output, and the return value is being used for checking whether the function's output is valid.
And the <> brackets are Generics stuff. Somewhat complex, and you shouldn't try to mess with it yet, probably.
Also, I'd recommend reading that book first before trying to code in C#. It explains what you're asking about. (there's a free ebook version on that site, btw.)
@Rachael
Nope. "<>" in C# is used for templates and template related stuff.
Oh and unlike in C++ templates are actually usable.
Thank <insert deity of your choice here> for Generics. Having to make a billion copies of a function just to have it accept different variable types is dumb.
I wish C#'s templates were as flexible as D's, though. D template are super flexible and waaaay easier to use than C# templates.
"hit" there is still being used for outputting the function's actual output, and the return value is being used for checking whether the function's output is valid.
And the <> brackets are Generics stuff. Somewhat complex, and you shouldn't try to mess with it yet, probably.
Also, I'd recommend reading that book first before trying to code in C#. It explains what you're asking about. (there's a free ebook version on that site, btw.)
@Rachael
Nope. "<>" in C# is used for templates and template related stuff.
Oh and unlike in C++ templates are actually usable.
Thank <insert deity of your choice here> for Generics. Having to make a billion copies of a function just to have it accept different variable types is dumb.
I wish C#'s templates were as flexible as D's, though. D template are super flexible and waaaay easier to use than C# templates.
Re: Using code from tutorials and plagarism
Ah, thanks for the correction then. I marked it through.
Re: Using code from tutorials and plagarism
Worth noting that C++ can do this via something likeRachael wrote:"Out" simply means that you are expected to pass a variable into the function and the function is allowed to modify it and send it back (sort of as a poor-man's "extra return value"). This seems to be something specific to C# - C/C++ does this by simply using pointers.
Code: Select all
void myFunc(int& myVal) {
}
Re: Using code from tutorials and plagarism
I need some help with debugging my if statement logic.
I wanted to make a condition where a probe cannot be rotated to a angle greater than the parent's base angle +/- ~81 (0.45f) degrees (for some reason the angle is stored from -1.0 to 1.0). The parent orients itself based on the normal of a plane that it moves around on. So I made the the following nested if statements. Everything else works except the limiting section. It just rotates as much as I want it to. What am I doing wrong with the marked with "<<<<<---this line" if statement?
I wanted to make a condition where a probe cannot be rotated to a angle greater than the parent's base angle +/- ~81 (0.45f) degrees (for some reason the angle is stored from -1.0 to 1.0). The parent orients itself based on the normal of a plane that it moves around on. So I made the the following nested if statements. Everything else works except the limiting section. It just rotates as much as I want it to. What am I doing wrong with the marked with "<<<<<---this line" if statement?
Code: Select all
void TiltFunction () //tilts the probe
{
if (transform.rotation.z <= transform.parent.rotation.z+0.45f || transform.rotation.z >= transform.parent.rotation.z-0.45f) //limits the tilt to +/-60 degrees <<<<<<---this line
{
if (Input.GetKey("w"))
{
transform.Rotate(0,0,tiltSpeed);
}
if (Input.GetKey("s"))
{
transform.Rotate(0,0,-tiltSpeed);
}
}
Debug.Log("Parent rotation is " + transform.parent.rotation.z);
Debug.Log("Probe rotation is " + transform.rotation.z);
}