Can we not use %s anymore?

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
wyverngem
Miko-Class Veteran
Posts: 615
Joined: Mon Oct 03, 2011 7:27 pm
Completed: Simple as Snow, Lady Luck's Due,
Projects: Aether Skies, Of the Waterfall
Tumblr: casting-dreams
itch: castingdreams
Location: USA
Contact:

Can we not use %s anymore?

#1 Post by wyverngem »

I was running my script for a calendar changer and I noticed that %s isn't working anymore. What gives? First it's not finding the variable, put it inside a init and it's not replacing the image based on the variable.

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "game/script.rpy", line 3, in script
    image cal_background = "cal_%s.png"%month
  File "game/script.rpy", line 3, in <module>
    image cal_background = "cal_%s.png"%month
NameError: name 'month' is not defined

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

Full traceback:
  File "game/script.rpy", line 3, in script
    image cal_background = "cal_%s.png"%month
  File "G:\Creative\VN\Renpy\renpy\ast.py", line 980, in execute
    img = renpy.python.py_eval_bytecode(self.code.bytecode)
  File "G:\Creative\VN\Renpy\renpy\python.py", line 1937, in py_eval_bytecode
    return eval(bytecode, globals, locals)
  File "game/script.rpy", line 3, in <module>
    image cal_background = "cal_%s.png"%month
NameError: name 'month' is not defined

Windows-7-6.1.7601-SP1
Ren'Py 7.1.3.1092
small_calander 1.0
Tue Jan 22 21:05:33 2019

User avatar
Imperf3kt
Lemma-Class Veteran
Posts: 3792
Joined: Mon Dec 14, 2015 5:05 am
itch: Imperf3kt
Location: Your monitor
Contact:

Re: Can we not use %s anymore?

#2 Post by Imperf3kt »

image cal_background = "cal_%s.png"%month

Doesn't look right to me, why is %month outside the quotation?
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Current project: GGD Mentor

Twitter

User avatar
trooper6
Lemma-Class Veteran
Posts: 3712
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: Can we not use %s anymore?

#3 Post by trooper6 »

Also % is Python script (though Python is now using format rather than %)...image is a Renpy line...so you can just do:

Code: Select all

default month = "june"
image cal_background = "cal_[month].png"
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?)
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

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: Can we not use %s anymore?

#4 Post by Remix »

Your error incidentally just says month is not defined, it does not say the %s isn't working... maybe add a - default month = "jan" - in your script.

I would though advise starting to use the syntax that trooper6 suggested.
Frameworks & Scriptlets:

User avatar
wyverngem
Miko-Class Veteran
Posts: 615
Joined: Mon Oct 03, 2011 7:27 pm
Completed: Simple as Snow, Lady Luck's Due,
Projects: Aether Skies, Of the Waterfall
Tumblr: casting-dreams
itch: castingdreams
Location: USA
Contact:

Re: Can we not use %s anymore?

#5 Post by wyverngem »

trooper6 wrote: Wed Jan 23, 2019 1:31 am Also % is Python script (though Python is now using format rather than %)...image is a Renpy line...so you can just do:

Code: Select all

default month = "june"
image cal_background = "cal_[month].png"
I'm not familiar with format, sadly.

I reviewed my code and I think it was because I was trying to use add cal_background on my screen instead of just add "cal %s"%month. However, add "cal [month]" works in a screen as well. I am really not sure since I tossed the original code. However, when I do remember it telling me that month wasn't defined when I was using default month right before it on the screen.

Anyways, it's working now.

Post Reply

Who is online

Users browsing this forum: Karrion, Majestic-12 [Bot]