Control BackImage using variable value

xabileug

Veteran
Veteran
Joined
Jul 1, 2014
Messages
103
Reaction score
21
I want to change the back image of a custom scene depending on the value of the variable. I made the input part here..

JavaScript:
/*
* @param CardBattle BackImages
* @desc set backimage depending on variable
* @type struct<backImage>
* @default {"images":"[]","vnBackImages":"0"}
* @parent dataType
*/

//=============================================================================
/*~struct~backImage:
* @param images
* @desc set image per variable value
* @type file[]
* @default []
* @require 1
* @dir img/pictures
* @parent otherType
*
* @param vnBackImages
* @desc set variable ID control
* @type variable
* @default 0
* @parent database
*/

but when i apply it on the part where the createBackground is.. nothing happens.. here's the code.

JavaScript:
Spriteset_CardBattle.prototype.createBackground = function() {
        this._backgroundSprite = new Sprite();
        var abc  = TMPlugin.Card.SBI.cardbattle;
        var index = abc.vnBackImages ? $gameVariables.value(abc.vnBackImages) - 1 : 0;
        var bgiName = index >= 0 ? abc.images[index] : null;
        this._backgroundSprite.bitmap = bgiName ?
            ImageManager.loadPicture(bgiName) : ImageManager.loadPicture('cardbattle');
        this._baseSprite.addChild(this._backgroundSprite);

    };

I think it is because i don't know how to properly call the parameters? i used a hashkey (i think)

JavaScript:
    TMPlugin.Card.SBI = {
        cardbattle : {images:[],vnBackImages:0},
    };

Thank you.
 
Last edited:

Eliaquim

Raze: The Rakuen Zero's Guardian!
Veteran
Joined
May 22, 2018
Messages
1,278
Reaction score
545
First Language
Portuguese - Br
Primarily Uses
RMMV
About the parameters, take a look at this and see if it helps.
 

xabileug

Veteran
Veteran
Joined
Jul 1, 2014
Messages
103
Reaction score
21
Hello. Thank you for the reply. I viewed your link..

i have the parse code too..
JavaScript:
(function() {
    // new line

    var parameters = PluginManager.parameters('TM_Card');

    var paramParse = function(obj) {
        return JSON.parse(JSON.stringify(obj, paramReplace));
    };

    var paramReplace = function(key, value) {
        try {
            return JSON.parse(value || null);
        } catch (e) {
            return value;
        }
    };

    var setBackImages = function(param) {
        param = paramParse(parameters[param]);
        return param instanceof Object ? param : {images:[],vnBackImages:0};
    };

    TMPlugin.Card.SBI = {
        cardbattle : setBackImages('CardBattle BackImages'),
    };
 // new line end
But then it's not being fetched properly.. i still get 'cardbattle' the default value in the bolean as image..
 

xabileug

Veteran
Veteran
Joined
Jul 1, 2014
Messages
103
Reaction score
21
i got this to work. I think the error was the line

Code:
var parameters = PluginManager.parameters('TM_Card');

//switched to
//var parameters = PluginManager.parameters('TMCard');
I also replaced vnBackImages to variableId

so im trying to use the same logic with variable controlled BGM.. i cant find where the event > system settings > change Battle BGM is located.. so i made this code to change the battle bgm

Code:
        var abc  = TMPlugin.SBM.cardmusic;
        var index = abc.variableId ? $gameVariables.value(abc.variableId) - 1 : 0;
        var bgmName = index >= 0 ? abc.name[index] : null;
        var bgm = {"name":bgmName,"pan":abc.pan,"pitch":abc.pitch,"volume":abc.pitch};
        if (bgmName !== null){
        AudioManager.playBgm(bgm);
        } else {
        BattleManager.playBattleBgm();
        }
i get the error Audiomanager not defined.
 
Last edited:

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

So ms store had an idea to nuke the the entire app when the file integrity is slightly broken.
Im on another months long scripting high. I wonder if I can go SSJS3?

Version Fille in english is now complete!
Download the game on itch.io:
Talk about it here: https://forums.rpgmakerweb.com/index.php?threads/120802/

Enjoy and share!
3am me was like.... Hey buddy, what if I told you, where we're going we don't need events? :LZSwink:
5pm me is like.... Was 3am me onto something? No! Must work on actual gameplay! Rabbit hole bad! :kaoback:
I'm thinking of having a scavenger-based way to learn advanced skills in my first game, and use the work I did for figuring out a skill grid/maze instead for an optional dungeon in the game.

Forum statistics

Threads
98,037
Messages
948,723
Members
129,292
Latest member
zenmai
Top