Copying instances?

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.
Post Reply
Message
Author
User avatar
valeatory
Regular
Posts: 36
Joined: Mon Apr 23, 2007 3:01 pm
Projects: Nightglove Institute, Monstrata Fracture
Organization: Astralore Games
Tumblr: valeatory
itch: astralore
Location: America
Contact:

Copying instances?

#1 Post by valeatory »

I have an inventory setup in my game where the player gets items using the predetermined function self.get, that simply appends whatever you get to the list of self.inventory. The only items you can get are instances (class weapon, class armor, class boots), and instances seem to be mutable. I am using the mutable-ness of it to tell the game whether the item is being used by changing self.used to True when equipped, and False when not. All of this seems to work fine, but I do have a problem that comes up when you get multiple of the same item. if you get two practswords, say, and you equip one, it will treat it like you equipped both because it is changing the only actual practsword variable. I know for things like lists you can copy them by saying practsword[:], but I know of nothing like that for instances. What should I do?
Nightglove Institute - Kidnapped students, forced to train to be secret agents and assassins!
Monstrata Fracture - Date cute monsters! But will you risk destabilizing the human plane of existence?

chronoluminaire
Eileen-Class Veteran
Posts: 1153
Joined: Mon Jul 07, 2003 4:57 pm
Completed: Elven Relations, Cloud Fairy, When I Rule The World
Tumblr: alextfish
Skype: alextfish
Location: Cambridge, UK
Contact:

Re: Copying instances?

#2 Post by chronoluminaire »

Sounds like you want the Python copy module. How to use it, plus warnings about using it (basically: it probably won't play well with rollback), can be found here: http://lemmasoft.renai.us/forums/viewto ... f=8&t=3031
I released 3 VNs, many moons ago: Elven Relations (IntRenAiMo 2007), When I Rule The World (NaNoRenO 2005), and Cloud Fairy (the Cute Light & Fluffy Project, 2009).
More recently I designed the board game Steam Works (published in 2015), available from a local gaming store near you!

User avatar
valeatory
Regular
Posts: 36
Joined: Mon Apr 23, 2007 3:01 pm
Projects: Nightglove Institute, Monstrata Fracture
Organization: Astralore Games
Tumblr: valeatory
itch: astralore
Location: America
Contact:

Re: Copying instances?

#3 Post by valeatory »

Thanks! It caused some problems with the way my game was figuring out what type an item was, but now it works great! Thanks a lot!
Nightglove Institute - Kidnapped students, forced to train to be secret agents and assassins!
Monstrata Fracture - Date cute monsters! But will you risk destabilizing the human plane of existence?

Post Reply

Who is online

Users browsing this forum: Bing [Bot]