Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
-
Westeford
- Regular
- Posts: 151
- Joined: Mon Jun 19, 2017 4:43 pm
- Completed: 12 Hours to Die
- Projects: Project Premonition
- itch: westeford
- Location: United States
-
Contact:
#1
Post
by Westeford » Sun Dec 12, 2021 1:44 am
So I'm trying to practice making an RPG battle system in Ren'Py. So I'm storing enemy names and stats like this
Code: Select all
define gakk_name = "Gakk"
define gakk_hp = 50
define gakk_atk = 1
And I want to import these stats into this
Code: Select all
define bad1_name = ""
define bad1_hp = 0
define bad1_atk = 0
then I thought, what if I had something like this
Code: Select all
define bad1 = ""
$ bad1_name = [bad1]_name
$ bad1_hp = [bad1]_hp
$ bad1_atk = [bad1]_atk
so if I made {bad1 = gakk}, bad1_name would search for {gakk_name} and so on.
I want to know how I could do this. I have no idea what to call this, but I hope I'm making some sense.
-
enaielei
- Regular
- Posts: 114
- Joined: Fri Sep 17, 2021 2:09 am
- Tumblr: enaielei
- Deviantart: enaielei
- Github: enaielei
- Skype: enaielei
- Soundcloud: enaielei
- itch: enaielei
- Discord: enaielei#7487
-
Contact:
#2
Post
by enaielei » Sun Dec 12, 2021 2:10 am
You should be using `default` instead of `define` if you're planning to modify these variables later on.
For what you want, I suggest using a `dict` instead, or better yet just make your own class.
Code: Select all
default entities = dict(
gakk=dict(name="Gakk", hp=50, atk=1),
jakk=dict(name="Jakk", hp=20, atk=5),
)
default current = "gakk"
label fight:
$ entity = entities[current]
$ name, hp, atk = entity["name"]. entity["hp"], entity["atk"]
"Your enemy is [name]. HP: [hp], Attack: [atk]"
label start:
$ current = "gakk"
call fight
"---"
$ current = "jakk"
call fight
"---"
$ current = "gakk"
call fight
"---"
-
zmook
- Veteran
- Posts: 421
- Joined: Wed Aug 26, 2020 6:44 pm
-
Contact:
#3
Post
by zmook » Sat Dec 18, 2021 2:20 am
FWIW, it is possible to do what you suggest (though you shouldn't. It's absolutely better to do what enaielei recommends).
Code: Select all
$ bad1_name = getattr(store, bad1+"_name")
colin r
➔ if you're an artist and need a bit of help coding your game, feel free to send me a PM
Users browsing this forum: Bing [Bot], Google [Bot]