- 112
- Posts
- 10
- Years
- Seen Nov 17, 2023
I'm changing Essential's default party screen and I'm looking for a way to have the screen remember the last Pokemon that was selected before it changed to the current selection. I was able to do this for the storage party screen (in PScreen_Storage) shown below:
And here's the code that allows this screen to remember the last selected pokemon on the right list when scrolling left/right between it and the lead pokemon (changes highlighted):
I figured I could easily do the same thing in PScreen_Party for the general party screen with a similar layout shown here:
The code section for this in PScreen_Party is similar enough to the section in PScreen_Storage that I thought I could easily create the same behavior, but it turns out it's much different than I hoped it would be. Here's what I have so far (changes highlighted):
All it does is default to the second slot (which has the value of "1" since slot 1 has a value of "0").
TL;DR: How can I set lastsel equal to currentsel in pbChangeSelection without it defaulting back to 1?
Also, this is version 16 FYI, but I checked between 16 and 17 and didn't see any big changes to the party screen code as far as I could tell.
Spoiler:
![[PokeCommunity.com] Make party screen remember last selected slot [PokeCommunity.com] Make party screen remember last selected slot](https://i.imgur.com/jUbO7v5.png)
And here's the code that allows this screen to remember the last selected pokemon on the right list when scrolling left/right between it and the lead pokemon (changes highlighted):
Spoiler:
Code:
def pbPartyChangeSelection(key,selection[S-HIGHLIGHT],lastsel[/S-HIGHLIGHT])# lastsel from pbSelectPartyInternal
case key
when Input::UP#LEFT
selection-=1
selection=6 if selection<0
when Input::DOWN#RIGHT
selection+=1
selection=0 if selection>6
when Input::LEFT#UP
if selection==6
#selection=5
#If CANCEL is selected, LEFT shouldn't do anything.
else
#selection-=2
#If any other slot is selected, move cursor to slot 0 (first slot)
selection=0
selection=6 if selection<0
end
when Input::RIGHT#DOWN
if selection==6
#selection=0
#If CANCEL is selected, RIGHT shouldn't do anything.
else
#selection+=2
[S-HIGHLIGHT]if selection == 0 #Sets selection to last selected pokemon on the right list if current selection is slot1
selection=lastsel
end[/S-HIGHLIGHT]
selection=6 if selection>6
end
end
[S-HIGHLIGHT]lastsel = selection #Updates the last selected pokemon by setting it equal to current selection[/S-HIGHLIGHT]
return selection
end
def pbSelectPartyInternal(party,depositing)
selection=@selection
pbPartySetArrow(@sprites["arrow"],selection)
pbUpdateOverlay(selection,party)
pbSetMosaic(selection)
[S-HIGHLIGHT] lastsel=1 #defaults lastsel to 1 (slot 2 in party screen)[/S-HIGHLIGHT]
loop do
Graphics.update
Input.update
key=-1
key=Input::DOWN if Input.repeat?(Input::DOWN)
key=Input::RIGHT if Input.repeat?(Input::RIGHT)
key=Input::LEFT if Input.repeat?(Input::LEFT)
key=Input::UP if Input.repeat?(Input::UP)
if key>=0
pbPlayCursorSE()
newselection=pbPartyChangeSelection(key,selection[S-HIGHLIGHT],lastsel[/S-HIGHLIGHT]) #lastsel from pbPartyChangeSelection
if newselection==-1
return -1 if !depositing
[S-HIGHLIGHT]elsif newselection==-2
selection=lastsel #Selects last selected pokemon on right list internally[/S-HIGHLIGHT]
else
selection=newselection
end
pbPartySetArrow(@sprites["arrow"],selection)
[S-HIGHLIGHT]lastsel=selection if selection>0#only sets lastsel value if selection isn't the lead pokemon[/S-HIGHLIGHT]
pbUpdateOverlay(selection,party)
pbSetMosaic(selection)
end
pbUpdateSpriteHash(@sprites)
if Input.trigger?(Input::C)
if selection>=0 && selection<6
@selection=selection
return selection
elsif selection==6 # Close Box
@selection=selection
return (depositing) ? -3 : -1
end
end
if Input.trigger?(Input::B)
@selection=selection
return -1
end
end
end
I figured I could easily do the same thing in PScreen_Party for the general party screen with a similar layout shown here:
Spoiler:
![[PokeCommunity.com] Make party screen remember last selected slot [PokeCommunity.com] Make party screen remember last selected slot](https://i.imgur.com/ji5tUX6.png)
The code section for this in PScreen_Party is similar enough to the section in PScreen_Storage that I thought I could easily create the same behavior, but it turns out it's much different than I hoped it would be. Here's what I have so far (changes highlighted):
Spoiler:
Code:
def pbChangeSelection(key,currentsel[S-HIGHLIGHT],lastsel[/S-HIGHLIGHT])
numsprites=(@multiselect) ? 8 : 7
case key
when Input::UP
begin
currentsel-=1
end while currentsel>0 && currentsel<@party.length && !@party[currentsel]
if currentsel>[email protected] && currentsel<6
[email protected]
end
currentsel=numsprites-1 if currentsel<0
when Input::DOWN
begin
currentsel+=1
end while currentsel<@party.length && !@party[currentsel]
if [email protected]
currentsel=6
elsif currentsel==numsprites
currentsel=0
end
when Input::LEFT
if currentsel>=6
#begin
#currentsel=0#-=1 For cancel button, not needed since new button doesn't scroll left/right.
#end while currentsel>0 && !@party[currentsel]
else
begin
currentsel=0#-=2 For switching left to lead pokemon
end while currentsel>0 && !@party[currentsel]
end
if currentsel>[email protected] && currentsel<6
[email protected]
end
currentsel=numsprites-1 if currentsel<0
when Input::RIGHT
if currentsel>=5
#currentsel+=1 For cancel button, not needed since new button doesn't scroll left/right.
else
#currentsel=1#+=2
[S-HIGHLIGHT]if currentsel == 0 # This conditional checks for the last selected pokemon and selects it again.
currentsel = lastsel
end[/S-HIGHLIGHT]
currentsel=6 if currentsel<6 && !@party[currentsel]
end
if currentsel>[email protected] && currentsel<6
currentsel=6
elsif currentsel>=numsprites
currentsel=0
end
end
[S-HIGHLIGHT] lastsel = currentsel[/S-HIGHLIGHT]
return currentsel
end
######################################
#Additional unchanged defs between these two blocks
######################################
def pbChoosePokemon(switching=false,initialsel=-1[S-HIGHLIGHT],lastsel[/S-HIGHLIGHT])
for i in 0...6
@sprites["pokemon#{i}"].preselected=(switching && i==@activecmd)
@sprites["pokemon#{i}"].switching=switching
end
@activecmd=initialsel if initialsel>=0
pbRefresh
[S-HIGHLIGHT]lastsel=1[/S-HIGHLIGHT]
loop do
Graphics.update
Input.update
self.update
oldsel=@activecmd
key=-1
key=Input::DOWN if Input.repeat?(Input::DOWN)
key=Input::RIGHT if Input.repeat?(Input::RIGHT)
key=Input::LEFT if Input.repeat?(Input::LEFT)
key=Input::UP if Input.repeat?(Input::UP)
if key>=0
@activecmd=pbChangeSelection(key,@activecmd[S-HIGHLIGHT],lastsel[/S-HIGHLIGHT])
end
if @activecmd!=oldsel # Changing selection
pbPlayCursorSE()
numsprites=(@multiselect) ? 8 : 7
for i in 0...numsprites
@sprites["pokemon#{i}"].selected=(i==@activecmd)
end
end
if Input.trigger?(Input::B)
return -1
end
if Input.trigger?(Input::C)
pbPlayDecisionSE()
cancelsprite=(@multiselect) ? 7 : 6
return (@activecmd==cancelsprite) ? -1 : @activecmd
end
end
end
All it does is default to the second slot (which has the value of "1" since slot 1 has a value of "0").
TL;DR: How can I set lastsel equal to currentsel in pbChangeSelection without it defaulting back to 1?
Also, this is version 16 FYI, but I checked between 16 and 17 and didn't see any big changes to the party screen code as far as I could tell.