Control BackImage using variable value

xabileug

Veteran
Veteran
Joined
Jul 1, 2014
Messages
120
Reaction score
28
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

Hakuen Studio
Veteran
Joined
May 22, 2018
Messages
1,612
Reaction score
976
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
120
Reaction score
28
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
120
Reaction score
28
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

Is there anyone who would like to resize some of sprites I've got and put them into MV sheet? I'm bad at that kind of things. I want to make a game, but I lack in resources and I'm bad at recolouring them, so my only option was to use a sprite maker from one game (Ive got permission to use it) but these are sprites from VX Ace and I only have MV. So, is there anyone interested in helping me?
Wow! This game looks great! Streaming now :D
Working on a system that allows you to define events in an easy to use text file format!!! Would you use such a thing? 0o
Have my fingers crossed, waiting for a discount sale on MZ on Steam.. Its normally around the corner during Halloween or x-mas season on Steam, if i remember right..

Forum statistics

Threads
104,483
Messages
1,006,625
Members
135,988
Latest member
Hypermear
Top