Examples of code and personal projects

Did you do like a 1-to-1 following of the tutorial, or close to it? If you did that, then you might want to next try to add some small new features to the project you made to make sure you truly understood what the code does.

2 Likes

Update: Now, I’ll be working on my gamemode on Garry’s Mod.

1 Like
DANG IT! I’m desperately trying to set up stamina, but I just can’t! Health and Armor have their own methods for Player and Entity classes, but stamina has never been one. I tried to set up stamina methods and integrate it into the player class, but it didn’t work. What a shame! Shame on me!
I’ve spent the entire afternoon on it! Seems like I’m just complicating the task.

I’ll try out later.

Perhaps you could look at an existing gamemode that adds stamina. I’m sure I’ve seen gmod mods that add a sprinting stamina bar.

1 Like
Nevermind, it was actually more simple than I thought. I just had to use HL2’s AUX power with Player:GetSuitPower(). Only problem is that it counts also for drowning, thus I’ll have to change it later.

I have finished the barebones (like 4%) of the Formicarium Project. It has a run time of 18 seconds, the link below has the Python file and incase you don’t trust me (you shouldn’t download python files from people you don’t trust) I have all the code in ‘formicarium_project_non_pyhton.txt’ that you can read and paste into a Python Shell. I have caught some errors and I am using one to cause Python to crash as a way to quit.


This link lasts one week.

If this is against the rules, feel free to smite this post that breaks the rules off the forum.

What is this? was this discussed before?

You can exit with sys.exit(exit_status) in python. Import the sys module to use it (which you didn’t do if I’m reading it correctly. Put import sys somewhere on the top of the file.).
enterinput.lower() will return enterinput in lowercase. str.upper is also a thing.
If one types in BACKGROUND you will still get the message used for unexpected input. That’s because the user didn’t write HELP, which means that the else after the help check fires. Use elif for the checks between the first if and the else so that once one check fires, the others don’t. Also, the check for unexpected input should be at the bottom of that if-elif chain.
e.g:

if enterinput == "QUIT":
    #blabla

elif enterinput == "BACKGROUND":
    #blabla

elif enterinput == "HELP":
    #blabla
        
elif enterinput == "ENTER":
    #blabla

else:
    #unexpected input

The user is also very unlikely to write sentences like «I get a Syntax Error when trying to run this» without differences. The in keyword can be used to search for elements in an array (such as strings or lists), if you still want to do it the way you are doing it.

1 Like

The help section are all placeholders as, unlike most of the updated code, there is nothing printed to the user. Once I’ve finished at least one country then I’ll revise the more confusing parts of the code. Thanks for the help!

It the product that the massive, failure, flowchart produced.

I think that this discussion fits better in this thread, to show off small coding learning projects.

2 Likes

Don’t often check development help, thought it was help for making mods for Python. Thanks for merging, would’ve never known this thread existed.

I’ll change the title to make it more general.

UPDATE: Changed.

1 Like

I made a non functioning Hangman. It makes a loop because it isn’t finished. Will be finished (hopefully) on Monday.
Filebin of the .py file (lasts 1 week):
https://filebin.net/nsyk2ttk3zx9fjyp

Source Code

import random

Game = True
while Game == True:

word = [“Array”, “Steam”, “Random”, “Import”, “Empires”, “Of”, “The”, “Undergrowth”, “Spore”, “Myrmecologist”, “Deoxyribonucleic”, “Plague”, “Pulsar”, “Ant”, “Thrive”, “Evolution”, “Ecosystem”, “Genetic”, “Microbe”, “Multicellular”, “Slug”, “Disco”, “Beetle”, “Uprising”, “Paradox”, “Star”, “Emperor”, “Espionage”, “Nemesis”, “Behaviour”, “Interactive”, “Dead”, “By”, “Daylight”, “Trapper”, “Wreith”, “Hag”, “Huntress”, “Myers”, “Shape”, “Nurse”, “Blight”, “Twins”, “Legion”, “Ghost”, “Face”, “Nightmare”, “Spirit”, “Executioner”, “Executioner”, “Pyramid”, “Head”, “Silent”, “Hill”, “Fallout”, “Elder”, “Scrolls”, “Ancestors”, “Humankind”, “Odyssey”, “Human”, “Revolutionary”, “Games”, “Studios”, “Aware”, “Awakening”, “Space”, “Ascended”, “Stage”, “Electronic”, “Arts”, “Hangman”, “Syntax”, “Error”, “Dungeon”, “Community”, “Biology”, “Xenophobia”, “Bacteriophage”, “Prion”, “Virus”, “Bacteria”, “Parasite”, “Agent”, “Gene”, “Disease”, “Microscopic”, “Transmission”, “Symptom”, “Infection”, “Infectivity”, “Lethality”, “Severity”, “Vector”, “Antibody”, “Antibiotics”, “Vaccine”, “Pandemic”, “Epidemic”]
#These are the words that’ll be used
lives = 10
#How many guesses you have
guessedletter = []
#Letters that the user has inputted
wordguess = []
#Shows player how long the word is
playerguess = “”
ChosenWord = random.choice(word).lower()
#The word
joinedWord = “”
for i in ChosenWord:
wordguess.append("?")
#Main
while (lives != 0 and “?” in wordguess):
joinedWord = “”.join(wordguess)
print(joinedWord)
print(“Please input a letter”)
letterinput = input().lower
if letterinput == wordguess:
print(“You got a correct letter, well done.”)
print(wordguess)
letterinput.append(playerguess)

for x in range(len(ChosenWord)):
    if playerguess ==  ChosenWord[x]:
      wordguess[x] = playerguess

if playerguess not in ChosenWord:
lives = lives - 1

print(“Do you want to play again? Y or N”)
responce = input()
if responce == “N”:
Game = False
else:
Game = True

The only difference is I fixed a Spelling mistake in the source code but not the file.

You should have used a code block as it looks like the formatting was entirely destroyed, which makes the python code invalid (thanks python people who decided that indentation is significant!).

import time and stuff

You can make code blocks like this:

```python
your code goes
here
```

edit: whoops, fixed valid to invalid

1 Like

I probably asked this before but am I the only one who finds low-level languages (C, C++) more intuitive than high-level/OOP languages (C#, Java)?

IDK I think most people just find the first language they code in to be the most intuitive.

For example I started coding in C# so now everything that’s very different from C# looks unintuitive to me. Like an explicit difference between pointers and variables for example. Apparently some people think it’s annoying that C# doesn’t tell you whether something is a pointer or a variable but for me it just sorta makes sense.
To this day I cannot pass a variable to a function in C++ without spending 20 minutes figuring out whether it should be a pointer or not. All I know about pointers is that C# just knows whether I meant to use a pointer.

So I guess all of our intuitions are just kinda weird in their own way.

I’ve only used Python so its the easiest I find to code in. Unless I’m tired, then its a nightmare.

If you make big systems in C, you’ll want to learn encapsulation strategies similar to OOP. Low level languages are only simple when you make simple programs. When you make much more complex software, you actually get more done with a more complex language as it supports building large systems better.

Surely if you practice enough in another language, you become proficient in it? I can’t really comment on this as I started writing C++, so for me moving to another language is basically noticing that most other languages only allow smart pointers to objects, so I just need to accept that I’m no longer in control of determining how a function receives the parameter objects. I really miss const references in C#. In C# you need to make intermediate interface types with read only properties, if you want to prevent a specific area of code from changing some object’s state.

1 Like

Here’s an example of code in C#. It creates an array containing the modern latin alphabet and digits.

using System.IO;
using System;

class Program
{
    static void Main(string[] args)
    {
        char[] array = new char[75]; /*This size is necessary because
        the for loop also counts the characters that are skipped*/
        
        for(int i = 0, j = 48; j <= 122; i++, j++)
        {
            if(j > 57 && j < 65 || j > 90 && j < 97)
            {
                continue; //skips values at [58, 64] and [91, 96]
            }
            
            array[i] = (char) j;
            Console.WriteLine(array[i]); //Prints all standard ASCII characters
        }
    }
}

Posting it here as a remainder for myself too.

sees hhyyrylainen’s reaction

@hhyyrylainen, what’s wrong?

1 Like