RPG Tutorial [1/unknown]

Post your own tutorials, guides and demos.

Post » Mon Sep 20, 2010 12:12 am

::RPG Tutorial - Actors, and experience points

In a rpg your character is going to level up and to keep track you need experience points. I don't have much knowledge of Construct but I have knowledge for programming/variable work.

If you're using python you need to setup an array, if your using just the event code listen

Python:
[code:1atxcsia]
actor = [];
actor[0,0] = "Mr.Cool"
actor[0,1] = 1 // Level
actor[0,2] = 70; // HP
actor[0,3] = 70 // HP Max
actor[0,4] = 0 // SP
actor[0,5] = 20 // SP Max
actor[0,6] = 5; // Strength
actor[0,7] = 9; // Power
actor[0,8] = 5; // Defence
actor[0,9] = 4; // Speed
actor[0,10] = 0; // XP
actor[0,11] = 0; // Slot number
[/code:1atxcsia]
[code:1atxcsia]
// Level/exp stuff
mrcool_exp = [];
mrcool_exp[0] = 50;
mrcool_exp[1] = 134;
// just keep doing the same until you reach Level 99/100.

level up code
if actor[0,10] >= mrcool_exp
actor[0,10] +=1;
// this is where you can display a level up message, and increase the stats.
[/code:1atxcsia]

Please note I come from a C++, GML, C# background, if my coding is somewhat wrong just correct me please.

I'll update this tutorial frequently.
B
2
G
4
Posts: 30
Reputation: 1,110

Post » Mon Sep 20, 2010 12:39 pm

[code:dhvx14i2]if actor[0,10] >= mrcool_exp
actor[0,10] +=1;[/code:dhvx14i2]

I believe you meant actor[0,1] +=1;

Carry on.
B
62
S
21
G
12
Posts: 1,910
Reputation: 13,155

Post » Mon Sep 20, 2010 8:15 pm

Hehe, my bad.

Anyway, was I right in executing an array variable? I'm really just trying to learn switch over to python.
B
2
G
4
Posts: 30
Reputation: 1,110

Post » Mon Sep 20, 2010 11:27 pm

Nice. I might use this for my game. Just a heads up, I know this is pseudo code, but I'm pretty sure it would go like this:

[code:opv9c5ma]1 # Level[/code:opv9c5ma]

instead of:

[code:opv9c5ma]1 // Level[/code:opv9c5ma]

# = comment in Python.
B
3
G
3
Posts: 23
Reputation: 946

Post » Tue Sep 21, 2010 12:08 am

Oh I see. I'm just used to "//" for comments.
I think ruby also uses "#" for comments.
B
2
G
4
Posts: 30
Reputation: 1,110

Post » Tue Sep 21, 2010 12:40 am

[quote="MysticTrunks":28afbaku]Anyway, was I right in executing an array variable? I'm really just trying to learn switch over to python.[/quote:28afbaku]
You could also create your own class.

[code:28afbaku]class Actor:
"""Definition of the player characters"""

def __init__(self):
self.name = ""
self.level = 0
self.hp = 0
self.hpmax = 0
self.sp = 0
self.spmax = 0
self.strength = 0
self.power = 0
self.defence = 0
self.speed = 0
self.xp = 0
self.slot = 0

[/code:28afbaku]
You create an instance of the class by referencing it:
[code:28afbaku]my_actor = Actor()[/code:28afbaku]

If all player characters start with a certain value, you would of course replace the appropiate values. Also, __init__ is not really a constructor, but works nearly the same way, because this method is automatically called as soon as the class is created. If you'd want to create a new instance of the class with certain values, you'd do this:
[code:28afbaku]class Actor:
"""Definition of the player characters"""

def __init__(self, name="", level=0):
self.name = name
self.level = level[/code:28afbaku]
Now you could create an instance either way:
[code:28afbaku]my_actor = Actor()
dewey = Actor("Dewey", 2)[/code:28afbaku]
You can still use a list to manage them:
[code:28afbaku]actors = []
actors.append(Actor("Dewey", 2))
actors.append(Actor())
actors[1].name = "Wanda"[/code:28afbaku]
And the levelup code could be realized as a method of the Actor class:
[code:28afbaku]class Actor:
"""Definition of the player characters"""

def __init__(self, name="", level=0):
self.name = name
self.level = level
self.xp = 0

def try_lvlup(self, exp):
if self.xp >= exp:
self.level += 1
[/code:28afbaku]
Again, referenced and stored in a list, you'd call:
[code:28afbaku]actors[1].try_lvlup(mrcool_exp)[/code:28afbaku]

But I guess it's just a matter of taste. I prefer the class-way for easier code maintaining (adressing actor[0].strength is more readable than actor[0, 5])
Image
B
23
S
8
G
10
Posts: 1,820
Reputation: 8,242

Post » Tue Sep 21, 2010 12:43 am

[quote="tulamide":3gmi2e16][quote="MysticTrunks":3gmi2e16]Anyway, was I right in executing an array variable? I'm really just trying to learn switch over to python.[/quote:3gmi2e16]
You could also create your own class.

[code:3gmi2e16]class Actor:
"""Definition of the player characters"""

def __init__(self):
self.name = ""
self.level = 0
self.hp = 0
self.hpmax = 0
self.sp = 0
self.spmax = 0
self.strength = 0
self.power = 0
self.defence = 0
self.speed = 0
self.xp = 0
self.slot = 0

[/code:3gmi2e16]
You create an instance of the class by referencing it:
[code:3gmi2e16]my_actor = Actor()[/code:3gmi2e16]

If all player characters start with a certain value, you would of course replace the appropiate values. Also, __init__ is not really a constructor, but works nearly the same way, because this method is automatically called as soon as the class is created. If you'd want to create a new instance of the class with certain values, you'd do this:
[code:3gmi2e16]class Actor:
"""Definition of the player characters"""

def __init__(self, name="", level=0):
self.name = name
self.level = level[/code:3gmi2e16]
Now you could create an instance either way:
[code:3gmi2e16]my_actor = Actor()
dewey = Actor("Dewey", 2)[/code:3gmi2e16]
You can still use a list to manage them:
[code:3gmi2e16]actors = []
actors.append(Actor("Dewey", 2))
actors.append(Actor())
actors[1].name = "Wanda"[/code:3gmi2e16]
And the levelup code could be realized as a method of the Actor class:
[code:3gmi2e16]class Actor:
"""Definition of the player characters"""

def __init__(self, name="", level=0):
self.name = name
self.level = level
self.xp = 0

def try_lvlup(self, exp):
if self.xp >= exp:
self.level += 1
[/code:3gmi2e16]
Again, referenced and stored in a list, you'd call:
[code:3gmi2e16]actors[1].try_lvlup(mrcool_exp)[/code:3gmi2e16]

But I guess it's just a matter of taste. I prefer the class-way for easier code maintaining (adressing actor[0].strength is more readable than actor[0, 5])[/quote:3gmi2e16]

That's great dude!
B
2
G
4
Posts: 30
Reputation: 1,110

Post » Tue Sep 21, 2010 1:02 am

I forgot to mention an important thing:

[] <-creates a one-dimensional list, not an array

So, to get a list working as an array you would need to do this:

[code:27nea85c]actor = []
actor.append("Dewey")
actor.append(1)
# etc for all values

actors = []
actors.append(actor)[/code:27nea85c]

A clear multi-dimensional array would be done with:
[code:27nea85c]actor = [[] for i in range(6)][/code:27nea85c]
This will create a list "actor" with 6 entries indexed from 0 to 5, and every entry is a list with no entries so far.
[code:27nea85c]actor[0].append("Dewey")
If actor[0][0] == "Dewey":
# let Malcolm know about it [/code:27nea85c]

But there's also a module esp for arrays, I didn't work with it yet: [url:27nea85c]http://docs.python.org/release/2.6.6/library/array.html[/url:27nea85c]
Image
B
23
S
8
G
10
Posts: 1,820
Reputation: 8,242

Post » Tue Sep 21, 2010 4:38 am

So to do something like this without Python, or with out loading a script, couldn't you make an internal array with @ array access?

+ System: For "points" from 1 to 9
+ System: mrgreen.Value('exp') Equal to LoopIndex("points")
-> mrgreen: Set 'current' to (1,2,3,4,5,6,7,8,9)@LoopIndex("points")

Haven't checked if it can take a string....
Image Image
B
161
S
48
G
89
Posts: 7,347
Reputation: 66,249

Post » Tue Sep 21, 2010 5:08 am

take a look at the second post here.
http://www.rpgrevolution.com/forums/ind ... ntry447958

Though, many if not anything can be done without python. Though, I don't think Mode7 can yet though.
B
2
G
4
Posts: 30
Reputation: 1,110

Next

Return to Your tutorials & example files

Who is online

Users browsing this forum: No registered users and 1 guest