Sup Medium! I’m bringing you guys another evening Py Log to chat about some progress with my Python journey (skipped Unity today because I couldn’t bother spending more time on my laptop). This is the last log of my 4-day break, so let’s make it a good one!
So What Have I Been Up To Lately?
Let’s get to the specifics, shall we? Firstly, I did some practice with regular expressions in Python. From what I can totally understand, regular expressions are just a form of checking for something in something. Which sounds cryptic, but it’s really just a tinier process for iterating and checking stuff. Thankfully, I have a tiny snippet for you guys to check out. Here it is:
import re # uses the regular expressions library in python
email = input("What's your email? ").strip()
if re.search(r"^\w+@(\w\.)?\w+\.(edu|com|org|)$", email): # creates a raw string, which will interpret any special characters like periods, slashes, etc.
print("Valid.")
# checks for only characters to the left of the @ (greater than 1 character, and any word character, which includes numbers and underscores)
# also checks for a something like "blank.something.edu" (forgot what it was called), if this is not true, then it will be ignored
# then checks for the domain name (greater than 1 character, and any word character, which includes numbers and underscores)
# then if the email ends in ".edu" (also checks for nothing after the .edu extension)
else:
print("Invalid.")
Loads of line comments, and for good reason. This program is cryptic as hell. Like, bro, do you see this? “(r”^w+…)”, like, WHAT EVEN IS THIS SUPPOSED TO BE??
Besides that, regular expressions are actually pretty nifty, and allow for a far better (cryptic and twisted) method to check stuff like inputs (as shown here)!
Next order of business is Unity. In the previous Py Log (Py Log #11), I talked about how I’d add in a code snippet of the shooting script someday. And that day is today:
I’ll go through this in depth so it makes sense. Firstly, we have our declarations, those being the isFullAuto boolean (checking if the user is holding the Left Mouse button down or not), the fireRate float (controls how fast the gun will fire), and a wacky looking Transform declaration. This (Transform gunBarrel) will declare where bullets will exit the gun model. We will have to declare where this exactly is, however it is needed at the moment to accurately set up our script for long-term use!
The gist of this script is that, if the player holds Left Mouse (determined by whether or not the button is held for a period of time, around a tenth of a second.), then we can start fullAuto firing. This will then cause the bullets to spawn from the gun barrel, traveling at a specified velocity and direction (physics is really kicking in now…). If they just press the Left Mouse button, then only one bullet will fire.
Overall, it’s a neat script. Next Wednesday, I’ll definitely get to actually programming the game, since I took the day off today on doing such.
Final Thoughts
That’s all for today! Before we shut down the studio, I gotta give another shoutout to Alexandra Grosu for 50 claps on the last Py Log. Also, thank you to Maximillian Isedal for being my first ever follower! There’s something about using up the maximum amount of claps for a given day on one of MY stories makes me super happy!
Anyways, thanks a bunch Medium. I’ll see you guys soon!