Please login or register.

Login with username, password and session length
Advanced search  

News:

This forum provides RSS feed. To query recent posts use this url. More...


Author Topic: Images for Savegames stay like on the first page  (Read 3826 times)

0 Members and 1 Guest are viewing this topic.

Darky

  • Supporter
  • Regular poster
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 109
    • View Profile
    • Spreadcamp
Images for Savegames stay like on the first page
« on: November 06, 2009, 10:35:04 PM »

I'm trying to implement images for the savegames in my game, and it ALMOST works already. The problem is, when I click the down button to go to the next page, then the images stay as they were and it doesnt show the appropriate images for this saveslot. This is the code of the SetState function, I highlighted the new lines by using a comment:

Code: WME Script
  1. function SetState()
  2. {
  3.   var BtnUp = this.GetControl("up");
  4.   var BtnDown = this.GetControl("down");
  5.   var BtnLoad = this.GetControl("load");
  6.  
  7.   BtnUp.Disabled = (ScrollOffset <= 0);
  8.   BtnDown.Disabled = (ScrollOffset+NumSlotButtons >= NumSavegames);
  9.   BtnLoad.Disabled = (SelectedSlot < 0);
  10.  
  11.   for(var i=0; i<NumSlotButtons; i=i+1)
  12.   {
  13.     var SaveSlot = ScrollOffset + i;
  14.     var SlotButton = this.GetControl(i+1);
  15.  
  16.         // this is new
  17.         var NewThumb = this.GetControl("pic" + SaveSlot);
  18.  
  19.     SlotButton.Pressed = (SaveSlot==SelectedSlot);
  20.     SlotButton.Text = SaveSlot;
  21.     if(Game.IsSaveSlotUsed(SaveSlot))
  22.     {
  23.       SlotButton.Text = SaveSlot+1 +". "+Game.GetSaveSlotDescription(SaveSlot);
  24.       SlotButton.Disabled = false;
  25.  
  26.         // this is new
  27.         NewThumb.SetImage("savegame:" + SaveSlot);
  28.     }
  29.     else
  30.     {
  31.       SlotButton.Text = SaveSlot+1 +". ---";
  32.       SlotButton.Disabled = true;
  33.  
  34.         // this is new
  35.         NewThumb.SetImage(null);
  36.     }
  37.   }
  38.  
  39. }
  40.  
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: Images for Savegames stay like on the first page
« Reply #1 on: November 06, 2009, 10:53:18 PM »

The var NewThumb = this.GetControl("pic" + SaveSlot); line is wrong. Should be something like var NewThumb = this.GetControl("pic" + SlotButton);
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

Darky

  • Supporter
  • Regular poster
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 109
    • View Profile
    • Spreadcamp
Re: Images for Savegames stay like on the first page
« Reply #2 on: November 06, 2009, 11:07:36 PM »

Thanks. Didn't work like that but was the push in the right direction:

var NewThumb = this.GetControl("pic" + i);

This works, apparently. Consider it fixed.
Logged

Darky

  • Supporter
  • Regular poster
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 109
    • View Profile
    • Spreadcamp
Re: Images for Savegames stay like on the first page
« Reply #3 on: November 07, 2009, 01:48:22 PM »

A new bug came up, I changed the mechanics a bit but now every button that has no savegame will not be disabled for some reason:



I have uploaded a Repro Project to check it out and experiment with:
Download the Repro Project
Logged

Darky

  • Supporter
  • Regular poster
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 109
    • View Profile
    • Spreadcamp
Re: Images for Savegames stay like on the first page
« Reply #4 on: November 07, 2009, 05:46:29 PM »

Problem solved, thanks to Mnemonic,

I had to replace the line
var SlotButton = this.GetControl(i+1);

with

var SlotButton = this.GetControl(ToString(i+1));


Quote from: Mnemonic
<Mnemonic> Change the line to: var SlotButton = this.GetControl(ToString(i+1));
<Mnemonic> GetControl can either get a number (index of a control) or a string (name of a control).
<Mnemonic> Right now if you send it 1, it assumes you want the first control, not a control named "1".
<Mnemonic> In WME demo it works, because the buttons are incidentally at the same index as their name.
Logged
 

Page created in 0.054 seconds with 20 queries.