Multiple Jump

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.
Message
Author
KarloPan
Newbie
Posts: 14
Joined: Thu Jun 22, 2017 8:16 pm
Contact:

Re: Multiple Jump

#16 Post by KarloPan »

Thank you!!!
This made it :D
I can't thank you enaugh again :D
is here some Voting system for good help? i want to give you five stars xD

KarloPan
Newbie
Posts: 14
Joined: Thu Jun 22, 2017 8:16 pm
Contact:

Re: Multiple Jump

#17 Post by KarloPan »

Hello Remix,
it worked really nice but i have annother short question,
What if i want to implement a if condition?
How do i do this?

I try "xx" : ["label_label", "THE label... Label", "ZZ" ,
if condition == True
"YY"

But this seems not to work...
Do i need to work with the add and del command?
and if yes how do i do this Exactly?
Can i only write
Del "xx"["ZZ"]??

User avatar
Remix
Eileen-Class Veteran
Posts: 1628
Joined: Tue May 30, 2017 6:10 am
Completed: None... yet (as I'm still looking for an artist)
Projects: An un-named anime based trainer game
Contact:

Re: Multiple Jump

#18 Post by Remix »

KarloPan wrote: Sat Jul 22, 2017 10:06 pmWhat if i want to implement a if condition?
How do i do this?

I try "xx" : ["label_label", "THE label... Label", "ZZ" ,
if condition == True
"YY"
Inside the location_info dict or within the choice menu building part it is reasonably complex and might not be easily readable, so:

The easiest way would be (similar to using compass paths) to use multiple keys and run the conditional outside
"xx" : ["label_label", "THE label... Label", "ZZ"] ,
"xxb" : ["label_label", "THE label... Label", "YY"] ,
...
current_location = "xx" if conditional == True else "xxb"

# that's basically a one liner that does
if conditional == True:
....current_location = "xx"
else:
....current_location = "xxb"

... or, if you are comfortable with list manipulation, you could do as you briefly conjectured

Code: Select all

if condition == True:
    if 'ZZ' in location_info['xx']:
        # the line above checks if it is there as the .remove( item ) function would error if item not found
        # rather than using 'del location_info['xx'][3]' we prefer .remove as we do not need to know where the value is
        location_info['xx'].remove('ZZ')
    # .append( item ) just adds a new item at the end
    # we should probably check if it is already there, just so as not to accidentally end up with multiples
    if 'YY' not in location_info['xx']:
        location_info['xx'].append('YY')
Take a look at This brief summary of python list functions for a quick lesson on handling list elements.

Just remember that our lists are referenced by dictionary name and key, so
Del "xx"["ZZ"]??
would throw errors, where-as
del location_info['xx'][4]
might not
Frameworks & Scriptlets:

KarloPan
Newbie
Posts: 14
Joined: Thu Jun 22, 2017 8:16 pm
Contact:

Re: Multiple Jump

#19 Post by KarloPan »

Hello there,
Thanks again :D

I tried first your code to only .append the direction to the room but i get this error
do not really know what this means "RevertableDict? :/
Did i missed to add something?

Code: Select all

 XX : ["label...label", "THE LABEL...label", "ZZ"],
I thought it should work like you said, at the end of the code it will append "YY" but it doesn't look like it works xD
Do i have to use an extra brace? like

Code: Select all

if "YY" not in location_info("XX"):
....location_info("XX"[3]).append("YY")

?

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "game/Player_House.rpy", line 347, in <module>
    if "YY" not in location_info("XX"):
TypeError: 'RevertableDict' object is not callable

-- Full Traceback ------------------------------------------------------------

Full traceback:
  File "lib/windows-i686/Player_House.rpyc", line 347, in script
  File "F:\renpy-6.99.12.4-sdk\renpy\ast.py", line 1656, in execute
    if renpy.python.py_eval(condition):
  File "F:\renpy-6.99.12.4-sdk\renpy\python.py", line 1749, in py_eval
    return py_eval_bytecode(code, globals, locals)
  File "F:\renpy-6.99.12.4-sdk\renpy\python.py", line 1743, in py_eval_bytecode
    return eval(bytecode, globals, locals)
  File "game/Player_House.rpy", line 347, in <module>
    if "YY" not in location_info("XX"):
TypeError: 'RevertableDict' object is not callable

Windows-8-6.2.9200
Ren'Py 6.99.12.4.2187
The Dark Plague Test 1.0
I just want to ask what i have done wrong xD
The other thing works Great

if conditional == True:
....current_location = "xx"
else:
....current_location = "xxb"

Small edit: If i want to change the name of the butten that is shown

Code: Select all

del location_info ["XX"] [2] # to delete in my example "THE LABEL...label"
add location_info ["XX"] [2] ("THE NOT label... LABEL") # to add a label in this position
#would that be right?!
and i use it, i need to great extra "key's" but this is fine for me :3
Thank you again for your help :D
Karlo

User avatar
Remix
Eileen-Class Veteran
Posts: 1628
Joined: Tue May 30, 2017 6:10 am
Completed: None... yet (as I'm still looking for an artist)
Projects: An un-named anime based trainer game
Contact:

Re: Multiple Jump

#20 Post by Remix »

Do not use (), use [] like I put in my code

if 'YY' not in location_info['xx']:

is a lot different than

if "YY" not in location_info("XX"):

P.S. add location_info ["XX"] [2] ("THE NOT label... LABEL") would do nothing except throw errors... google python lists and dictionaries for correct ways to do it

If you still have problems you might need to use multiple keys per locations as suggested.
I would actually suggest this as it keeps the code readable and allows you to define the lot in one sensible place
You could even add comments
...
# the weird door before we have the golden key
"xx" : ["label_label", "THE label... Label", "ZZ"] ,
# the weird door once we have the key and the can of oil
"xxb" : ["label_label", "THE label... Label", "YY"] ,
...

btw
You might get some snags with the Revertable not allowing some features of normal dicts
I've not got time tonight to check which methods a RevertableDict holds... some info anyway

When Ren'py saves stuff it uses a methodology called Pickle which is rather similar to Json in that it does not maintain full ordered integrity of stored data. For instance, if you *could* and did put in a normal python list in [1,2,3] it might well come back out as [3,1,2] or somesuch. To prevent calamities with data getting mangled, Pickle will not allow objects that use certain methods of storing data.
To get around that Ren'py uses a slimmed down version of List, Set and Dict called Revertable{obj} which peskily do not hold all the same functionality as pure python objects; lists etc
Frameworks & Scriptlets:

Post Reply

Who is online

Users browsing this forum: IrisColt