0% found this document useful (0 votes)
9 views

Expanded Python Roblox Lua Tutorials

Uploaded by

alihazem201111
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

Expanded Python Roblox Lua Tutorials

Uploaded by

alihazem201111
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

# Python Tutorials

## Basics

### Variables and Data Types


Variables store information in Python, and their types can change dynamically.

```python
# Example
x = 10 # Integer
x = "Now I'm a string!" # String

# Different data types


integer = 5
floating_point = 3.14
boolean = True
string = "Hello, World!"

print(f"Integer: {integer}, Float: {floating_point}, Boolean: {boolean}, String:


{string}")
```

### Lists and Dictionaries


```python
# Example: Lists
fruits = ["Apple", "Banana", "Cherry"]
for fruit in fruits:
print(fruit)

# Example: Dictionaries
person = {"name": "Ali", "age": 25, "city": "Karachi"}
print(f"{person['name']} lives in {person['city']}.")
```

### Advanced Conditionals


```python
# Example
number = 10
if number % 2 == 0:
print(f"{number} is even.")
else:
print(f"{number} is odd.")
```

## Advanced Loops and Iterations


```python
# Nested Loops Example
for i in range(3):
for j in range(2):
print(f"i={i}, j={j}")
```

### Functions with Keyword Arguments


```python
# Example
def introduce(name, age=18):
print(f"My name is {name} and I am {age} years old.")
introduce("Ali", 25)
introduce("Sara")
```

## Intermediate

### File Handling with JSON


```python
# Example
import json

data = {"name": "Ali", "age": 25}


with open("data.json", "w") as json_file:
json.dump(data, json_file)

with open("data.json", "r") as json_file:


loaded_data = json.load(json_file)
print(loaded_data)
```

### Classes with Inheritance


```python
# Example
class Vehicle:
def __init__(self, brand, model):
self.brand = brand
self.model = model

def info(self):
print(f"Vehicle: {self.brand} {self.model}")

class Car(Vehicle):
def start_engine(self):
print("Engine started!")

car = Car("Tesla", "Model S")


car.info()
car.start_engine()
```

### Decorators
```python
# Example
def greet_decorator(func):
def wrapper(name):
print("Hello!")
func(name)
print("Goodbye!")
return wrapper

@greet_decorator
def greet(name):
print(f"How are you, {name}?")

greet("Ali")
```

---
# Roblox Lua Tutorials

## Advanced Topics

### Tables and Metatables


```lua
-- Example: Tables as arrays and dictionaries
local fruits = {"Apple", "Banana", "Cherry"}
for i, fruit in ipairs(fruits) do
print(i, fruit)
end

-- Metatable example
local t = {a = 1}
local mt = {
__index = function(table, key)
return key .. " not found!"
end
}
setmetatable(t, mt)
print(t.b) -- Output: b not found!
```

### Advanced Events


```lua
-- Example: Connecting multiple events
local part = script.Parent

part.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
print(hit.Parent.Name .. " touched the part!")
end
end)
```

### Working with Cameras


```lua
-- Example
local camera = game.Workspace.CurrentCamera
camera.CameraType = Enum.CameraType.Scriptable
camera.CFrame = CFrame.new(Vector3.new(0, 10, 0))
```

### Animating GUI Elements


```lua
-- Example
local frame = script.Parent

for i = 1, 100 do
frame.Position = UDim2.new(0, i, 0, 0)
wait(0.05)
end
```

### Game Monetization: Developer Products


```lua
-- Example
local MarketplaceService = game:GetService("MarketplaceService")
local productId = 123456
MarketplaceService.PromptProductPurchaseFinished:Connect(function(player, id,
wasPurchased)
if id == productId and wasPurchased then
print(player.Name .. " purchased the product!")
end
end)
```

You might also like