Creating fake Code is hard

lazyredragon

Well-known member
Joined
Feb 3, 2019
Messages
144
Points
83
okay so in the book God of lies a video game creator finds himself in you guessed it his game with the power to shift stuff using code making him all powerful and junk so my friend just told me to use Linux command prompts and alter them for the story cause they are easier to understand ugh she's so awesome!

just putting this here if anyone is writing a book like that
 

S.D.Mills

Member
Joined
Feb 6, 2019
Messages
43
Points
18
I feel like that kind of story would be very hard to write if you aren't familiar with various things involving game creation. I work in the video game industry, so feel free to ask anything you want from me.
 

lazyredragon

Well-known member
Joined
Feb 3, 2019
Messages
144
Points
83
:giggle: thanks! I hope you don't mind me shamelessly taking advantage of this consultation! First question can a bug seriously damage a script to the point it looks like a virus?
 

S.D.Mills

Member
Joined
Feb 6, 2019
Messages
43
Points
18
A script is a piece of code. It cannot be edited, so it can't be damaged.

Can a bug look like a virus?
It would depend on what you mean. For example, you could have a game that runs on a server (as opposed to a client-only game). A bug that causes a secondary bug could happen. Theoretically, you could have a gameobject with a script running those only causes visible symptoms when it interacts with a player character. Every time an instance of that buggy gameobject interacts with a player, that player would be affected and experience whatever the symptoms of the bug are. In that sense, it wouldn't be a virus, but it would behave in a similar fashion.
 

lazyredragon

Well-known member
Joined
Feb 3, 2019
Messages
144
Points
83
kk That goes in line with the story,:D next one before i can think of anything else what exactly causes a bug? from what I've gathered it can be as little as a typo to something massive
1549529997013.png
 

Alverost

Eternal Procrastinator
Staff member
Joined
Jan 1, 2019
Messages
1,071
Points
153
kk That goes in line with the story,:D next one before i can think of anything else what exactly causes a bug? from what I've gathered it can be as little as a typo to something massive
View attachment 562
Bugs can appear for different reasons. Typically from error inside the code; Syntax Error, Logic Error and etc.
 

S.D.Mills

Member
Joined
Feb 6, 2019
Messages
43
Points
18
In games, there are bugs and there are mistakes.

A mistake is where something works correctly but a human did something they shouldn't have. For instance, making all the in-game premium items super cheap.

A bug is an unintended consequence of a piece of code in specific edge cases. Buffer overflows are the most common. Overflows happen when a variable keeps growing until it starts to take up more memory than is allocated to the game. In this case, it will either cause bits of code to be executed by unrelated gameobjects, or it will cause a memory leak which crashes the game if left alone long enough.

In other words, a bug happens when a programmer didn't think of all possible outcomes of their code and therefore did not compensate for an edge case. Then, it often turns out that edge case happens to be something players do every five minutes. Boom. Bug.
 

lazyredragon

Well-known member
Joined
Feb 3, 2019
Messages
144
Points
83
Ah
Bugs can appear for different reasons. Typically from error inside the code; Syntax Error, Logic Error and etc.
In games, there are bugs and there are mistakes.

A mistake is where something works correctly but a human did something they shouldn't have. For instance, making all the in-game premium items super cheap.

A bug is an unintended consequence of a piece of code in specific edge cases. Buffer overflows are the most common. Overflows happen when a variable keeps growing until it starts to take up more memory than is allocated to the game. In this case, it will either cause bits of code to be executed by unrelated gameobjects, or it will cause a memory leak which crashes the game if left alone long enough.

In other words, a bug happens when a programmer didn't think of all possible outcomes of their code and therefore did not compensate for an edge case. Then, it often turns out that edge case happens to be something players do every five minutes. Boom. Bug.
i get it so its like a feed back loop for human error!

So if for instance a character adds/alters code (Though imppoossible a dragon can dream) willy nilly in a world thats basically a game he is trapped in the feed back might cause a bug
 

S.D.Mills

Member
Joined
Feb 6, 2019
Messages
43
Points
18
Yes, that could happen. Also, it IS possible to edit the code as long as it the code edited is not currently instantiated and the system is built in such a way that you can edit text files directly from inside the game. Also, for instance, if the system allowed for direct interaction with the OS from inside the game (no reason I can think of that anyone would create such an absurd feature), then you could theoretically access the CLI for the OS. But keep in mind that the user would only be capable of accessing system operations allowed to the user account that the game process is executed on. There would never be a reason for a game to run on a process of a user account with very high system permissions. Though, in theory, there are ways to hack your account into higher permission levels. Such a thing would be highly technical to explain, but I can explain it if you want.
 

Teivel

New member
Joined
Jan 1, 2019
Messages
12
Points
3
I'd like to add a bit on Linux command prompt code, if you wanted to make very human readable code, the you should really use pseudo code, which is basically a very high level instruction on what the computer should do, ie. Make a Fireball. It isn't code per se, but it conveys the idea of what it should do, like a recipe. Natural language processing (what Siri and other digital assistants use) could interpret pseudo code and make a real script in a sci-fi environment. It has problems; when you code you want to have some degree of control over the outcome, with NLP, you have ambiguities that the machine would have to evaluate and may produce undesirable outcomes (bugs or mistakes). It has the advantage of being faster to code than normal, because the machine does more work on the low level stuff, and you could integrate it as the trade-off the programmers took in order to make something very complex, like a very realistic VR game.

If you want some guidelines on writing pseudo code, then you could look at Python's PEP 8 guidelines, whose purpose is to make code easier to read.

My knowledge comes from self teaching myself programming, I'm a math/computer guy, so if you want knowledge about theory and efficiency I'd be pleased to help!
 

Teivel

New member
Joined
Jan 1, 2019
Messages
12
Points
3
One example of the trade-off you make with human readable code is this:

In C/C++ you need to declare a variable before using it. ie.
C:
int myInteger = 0;

In Python and JavaScript you can skip that and just say:
Python:
myInt = 0

Let's say you have a function that adds to the player health when it drinks a potion:
Python:
def drinkPotion(player, potion):
    player.health += potion.effectiveness
    potion.destroy()

If you made a typo and instead of player.health, you just wrote health, it would create a new variable and store the value there, not healing the player, in C, that would not happen because the variable was not explicitly created and thus the program would fail (this is a flawed example as in Python this to would fail, but because the variable health contains no value at that point). Typos in Python and other high level languages are much more dangerous than in low level languages because the program still runs most of the time, in low level languages that doesn't happen as often, but they are susceptible to other mistakes.

A bug not caused by a typo can be, for example making a mutable object for certain things like a bullet, and not copying it. In this case you would be referencing the exact same object, leading to a gun that can only fire once, or that every time it fires the bullets stack onto each other leading to a very massive bullet.
 
Last edited:

S.D.Mills

Member
Joined
Feb 6, 2019
Messages
43
Points
18
To clarify, in JavaScript, you have to instantiate the variable, because a variable is an object, and all objects must be instantiated because in JS everything is an object. I know next to nothing about Python.

Teivel makes a good point about mutability. Mutation is a serious problem for games, as writing immutable code for a game would be a huge undertaking that development teams normally cannot afford. It's why they usually use what is called "Object-Oriented" programming. While OOP is convenient, it means you must test against every use case, which is ultimately impossible.
 

Teivel

New member
Joined
Jan 1, 2019
Messages
12
Points
3
To clarify, in JavaScript, you have to instantiate the variable, because a variable is an object, and all objects must be instantiated because in JS everything is an object. I know next to nothing about Python.

Teivel makes a good point about mutability. Mutation is a serious problem for games, as writing immutable code for a game would be a huge undertaking that development teams normally cannot afford. It's why they usually use what is called "Object-Oriented" programming. While OOP is convenient, it means you must test against every use case, which is ultimately impossible.

I've read that in JS you can do both:
JavaScript:
var myVar = 100;
let myOtheVar = 200;
And (although it is not advised):
JavaScript:
thisVar = 300;

I've heard that it produces to many errors as it declares that variable global, and it is usually not allowed in interpreters, but it's still something you can do in theory.
 

Teivel

New member
Joined
Jan 1, 2019
Messages
12
Points
3
Ah


i get it so its like a feed back loop for human error!

So if for instance a character adds/alters code (Though imppoossible a dragon can dream) willy nilly in a world thats basically a game he is trapped in the feed back might cause a bug

A bit of programming Jargon, more on Tech Terms:

Tech terms:
A syntax error is an error in the source code of a program. Since computer programs must follow strict syntax to compile correctly, any aspects of the code that do not conform to the syntax of the programming language will produce a syntax error.
(Basically a typo)
Python:
player.health = 100;

if player.attacked == True:
    player.h -= 10
Usually the code will not run unless you accidentally type another variable's name, which can happen, but is an edge case.
Tech Terms:
A logic error (or logical error) is a mistake in a program's source code that results in incorrect or unexpected behavior. It is a type of runtime error that may simply produce the wrong output or may cause a program to crash while running.
Python:
# Wrong Code
def bad_average(a, b):
    return a + b / 2
   
# Good code
def average(a, b):
    return (a + b) / 2
It can come from a typo, or a confusion of the programmer, a typical beginners mistake is accessing the first list element as firstElement = list.at(1), but that is actually the second element, as the index starts from 0.
Tech Terms:
A runtime error is a program error that occurs while the program is running.
Python:
myNumber = input("Give me a number: ")

# Convert Text to a Number
myNumber = float(myNumber)

print(myNumber + 5)
If the person using this program were to input a word instead of a number, this program would fail during runtime, thus making this a runtime error. The proper way to write this code would be with error catching, but this takes a lot longer:
Python:
valid = False
myNumber = None

while not valid:
    try:
        myNumber = input("Give me a number: ")
        # Convert Text to a Number
        myNumber = float(myNumber)
        valid = True
    except ValueError:
        print(myNumber, "is not a valid number")
        valid = False
       
print(myNumber + 5)
Tech Terms:
A memory leak is like a virtual oil leak in your computer. It slowly drains the available memory, reducing the amount of free memory the system can use. Most memory leaks are caused by a program that unintentionally uses up increasing amounts of memory while it is running. This is typically a gradual process that gets worse as the program remains open. If the leak is bad enough, it can cause the program to crash or even make the whole computer freeze.
Python:
enemies = list()

while running == True:
    if new_enemy == True:
        enemies.append(make_new_enemy())
        new_enemy = False
Fairly simple Game code, but if you forget to pop the enemies out of the list as they get killed or you move to a new area you have a very big memory leak.

I'm using python because it's easy to read for beginners, and I'm also doing some things inefficiently in order to make it obvious what the code is doing. So don't think this is how real code looks like, Python is pretty readable, but not as much as this. My code is a mess, but if you want some references, here you can see some maze generator code I wrote.
 

S.D.Mills

Member
Joined
Feb 6, 2019
Messages
43
Points
18
I've heard that it produces to many errors as it declares that variable global, and it is usually not allowed in interpreters, but it's still something you can do in theory.

It's possible I'm mistaken and that it is allowed in the ECMA spec, but I know it's not allowed at runtime for any engine I've used (V8, Node, SpiderMonkey).
 

RSPrince

New member
Joined
Feb 9, 2019
Messages
4
Points
3
okay so in the book God of lies a video game creator finds himself in you guessed it his game with the power to shift stuff using code making him all powerful and junk so my friend just told me to use Linux command prompts and alter them for the story cause they are easier to understand ugh she's so awesome!

just putting this here if anyone is writing a book like that
I would then suggest going a different route, such as make your own code ie use webdings, wingdings or some other supported symbol font, then write the action of what you want the code to do, and ta-da you know have your own code language per say. Otherwise all those who actually code are gonna criticize everything you write, so if it is done your own way, what can they say (of course a lot) you should use the code as a support and not be to worried about the mechanics of the code per say, unless you love to code then go all for it. To the general population, reading code is like jargon, you use a form of symbol fonts to create the mystical-ism of coding, and those who recognize the font, will know what you type on unless you encode that too to throw off people. Just something to think about.

In regards,
R. S. Prince
 
Last edited:

Ai-chan

Queen of Yuri Devourer of Traps
Joined
Dec 23, 2018
Messages
1,413
Points
153
okay so in the book God of lies a video game creator finds himself in you guessed it his game with the power to shift stuff using code making him all powerful and junk so my friend just told me to use Linux command prompts and alter them for the story cause they are easier to understand ugh she's so awesome!

just putting this here if anyone is writing a book like that
How about checking out some easy to learn programming scripts such as python? Judging from your description, it sounds like you only need scripts, not full coding. So it can be as easy as:

Item name is Blade of Axes.

(call: $axebladeproperties)
(set: $axebladesharpness = 50)
(set: $axebladetoughness = 100)
(set: $axebladestrengthreq = 5)
(set: $axebladebonusxp = xpgain + 100)

Scripts are generally logical, so if you can think of the flow, you can think of how to programme it. Game developers actually use scripts to change various properties of their games. Programming language is used to alter the engine to fit the game they want to make, but for changing items, characters, descriptions or various stats in the game, scripts are faster and preferable, and you don't run the chance of breaking the game when you only want to make small changes.
 

lnv

✪ Well-Known Hypocrite
Joined
Dec 24, 2018
Messages
492
Points
133
okay so in the book God of lies a video game creator finds himself in you guessed it his game with the power to shift stuff using code making him all powerful and junk so my friend just told me to use Linux command prompts and alter them for the story cause they are easier to understand ugh she's so awesome!

just putting this here if anyone is writing a book like that

What you want sounds a lot like javascript, which is compiled at runtime and can be easily modified midruntime.

For example, if you are on Chrome, click Ctrl+Shift+I, and copy the following into the window:

JavaScript:
setInterval(function() {document.querySelector('a[data-user-id=\'3851\']').style.fontSize=(parseInt(document.querySelector('a[data-user-id=\'3851\']').style.fontSize||0) + 5) + 'px'; },1000);

Hit enter and scroll to the top of the screen.

Now see what happens, don't worry when you refresh the page it'll be gone.
 

S.D.Mills

Member
Joined
Feb 6, 2019
Messages
43
Points
18
I don't think @lazyredragon is looking for code exactly. It sounded to me like they were asking how things work, so they can explain actions and situations in a way that is plausible while avoiding showing any actual code, which is honestly unnecessary.
 
Top