[Drag/Drop issue]About The timing of store.variables got updated during an interaction

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
aere_ioke
Newbie
Posts: 1
Joined: Sun May 23, 2021 10:48 am
Contact:

[Drag/Drop issue]About The timing of store.variables got updated during an interaction

#1 Post by aere_ioke »

Hi, Aere there.
Eh, Sorry to ask, but while building my project a problem really bothered me and I really would like to get some insights and advices from you:

====What I intended to do:
I'm building a card game using drag and drop features, and I want it work similarly to Slay the Spire, especially in following 2 features:
1. Evaluate card attribute after a successful drop:
Cards have costs, and after playing 1 card from hand deck, evaluate if there are enough energies left to play remaining cards, and make those cards not draggable once their costs greater than energies left.
2. Hold the screen rather than end it with a single turn interaction:
Like in Slay the Spire, screen changes only when the opponents down(or you lose), and you can play as many cards as you want before you hit the "End turn" button


====What I have tried:
I try to figure it out with a drag feature and some dragged function:

Code: Select all

call screen battlefield()

Code: Select all

screen battlefield():
	drag:   #The card in hand deck
		as hand_slot_1
        	drag_name hand_deck[0].name
        	droppable False
        	dragged normalcard_dragged
		xysize (210,185)
        	pos (210,530)
		frame:
			background hand_deck[0].smallface
			text hand_deck[0].name text_align .5 xalign .5 xsize 180 color "#0B0200"
			text hand_deck[0].info pos(15,150) color "#0B0200"
			text str(hand_deck[0].cost) size 32 color "#0B0200" pos (170,15)
	...  #(some other codes to build the slot for dropping a card)

Code: Select all

def normalcard_dragged(drags, drop):
        if not drop:
            card_movebackinstantly(drags, drop)
            return
        if drags[0].drag_name[0:5]=="Blade" and drop.drag_name[0:3]=="att":     #In game want only Blade card go into attack slots
            drags[0].snap(drop.x,drop.y, delay=0.1)
            drags[0].draggable = False
           
            for i in full_card_list:         #Here's how I try to calculate: use card's name as a clue to retrieve cost from list and calculate how many energies left
            	if drags[0].drag_name==i.name:
                	store.currentenergy=store.currentenergy-i.cost
        ...   #some codes to compare each card's cost and energies left and decide whether to make them not draggable 
            return
        else:
            card_movebackinstantly(drags, drop)
            return
And that's where the problem I met: the store.currentenergy variable seems unchanged(remains to be the initial value) after dropping a card successfully.
I add a text to show the value, and then noticed the store.currentenergy variable became correct after executing a following renpy.call_in_new_context statement
(Which I use it to act some performance)

Code: Select all

renpy.call_in_new_context("ability_activate",actor="Ivan")

Code: Select all

label ability_activate(actor):
    show screen ability_activate(actor)
    pause 2.5
    return

Code: Select all

screen ability_activate(actor):
    frame:
        add "Card/"+actor+"_skill.png"
        at ability_act
        timer 2 action Hide('ability_activate')
transform ability_act:
    yoffset 720
    on show:
        alpha 0.0
        easein 0.7 yoffset 0 alpha 1.0
    on hide:
        easeout 0.3 yoffset -360 alpha 0.0
This makes me wonder if the problem is caused by the fact that the variables only get updated when current interaction ends, which means not possible to achieve 1 and 2 simultaneously, I suppose. As I want the screen hold, it seems I can't end the screen interaction to get variables updated.

So I really would like to get some help from you all and hope someone could give me some advice how to achieve 1 and 2 simultaneously.
Big thanks!

Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot], voluorem