Drag and Drop Screen not reloading[Solved]

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
l1997
Newbie
Posts: 15
Joined: Thu Dec 28, 2017 10:42 am
Contact:

Drag and Drop Screen not reloading[Solved]

#1 Post by l1997 »

I have made a screen with a drag and drop component which takes dynamic data.

Code: Select all

screen drag_drop_screen():
    # A map as background.
    add "bgmarket"
    python:
        for i in range(0, len(inputs)):
            if not (BigPuzzle.get_child_by_name("name%s"%inputs[templist[i]][1]) or (inputs[templist[i]][1] in donelist)):
                print(inputs[templist[i]][1])
                print(donelist)
                print(templist)
                BigPuzzle.add(Drag(d=Text("[inputs[%d][0]]"%templist[i], style="optioncolor"),drag_name="name%s"%inputs[templist[i]][1]))
            temp2 = BigPuzzle.get_child_by_name("name%s"%inputs[templist[i]][1])
            if(temp2):
                temp2.snap(100,50+70*i)
        if not (BigPuzzle.get_child_by_name("dropbox")):
            BigPuzzle.add(Drag(d=im.Scale("postbox.png",200,400),drag_name="dropbox",draggable=False,dropped=item_dropped))
        temp=BigPuzzle.get_child_by_name("dropbox")
        temp.snap(900,300)
    add BigPuzzle
And I call the same screen from different levels with different data:

Code: Select all

$inputs = [['Val1',0],['Val2',1],['Val3',2],['Val4',3],['Val5',4]] //Different values for different levels
    python:
        donelist=[]
        templist=[]
        inlist=[]
        for i in range(0, len(inputs)): //The following loops are for making a random list from given list
            inlist.append(i)
        for i in range(0, len(inputs)):
            mychoice = renpy.random.choice(inlist)
            templist.append(mychoice)
            inlist.remove(mychoice)
    call screen drag_drop_screen()
    stop music
    "Completed Remittance Level Easy"
It works fine when I first load the screen. But if I quit to main menu from within the screen, then loading the screen from some other level makes the screen load with the values of the earlier inputs. Reloading the game gets the correct inputs. How can I make the screen loading get the correct values for drag items?

init python block:

Code: Select all

init python:
	inputs=[]
    	templist=[]
    	donelist=[]
    	BigPuzzle = DragGroup()
Last edited by l1997 on Wed Jan 24, 2018 11:05 am, edited 1 time in total.

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: Drag and Drop Screen not reloading

#2 Post by Remix »

I would suggest moving all the randomizing logic inside the screen and pass in the inputs as a parameter...

With that part of code inside the screen, it should run at each call/show and not rely on other external globalized variables.

Additionally, you could dispense with the inlist/templist and shuffle a range (if I read your code right)

Pseudo code:

Code: Select all

screen drag_drop_screen( inputs = [] ):
    # input indices as a shuffled sample
    default shuffled_idxs = renpy.python.random.Random().sample( range( len(inputs) ), len(inputs) )
    text "[shuffled_idxs]"
For rollback/save remembering the shuffle, try renpy.python.rng.sample(range( len(inputs) ), len(inputs) )
Frameworks & Scriptlets:

l1997
Newbie
Posts: 15
Joined: Thu Dec 28, 2017 10:42 am
Contact:

Re: Drag and Drop Screen not reloading

#3 Post by l1997 »

In my drop logic, I need to remove the items if dropped in the correct order. Wouldn't this method reload all the drag items which includes the ones removed?

l1997
Newbie
Posts: 15
Joined: Thu Dec 28, 2017 10:42 am
Contact:

Re: Drag and Drop Screen not reloading

#4 Post by l1997 »

I solved it. Anyways, thanks for the help. I solved it by simply redeclaring the draggroup again in the main code before calling the screen. This ensured that everytime the screen was called, the draggroup was empty and refilled with my dynamic text.

Code: Select all

$BigPuzzle=DragGroup()
call screen drag_drop_screen()

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot]