How do I set set a variable that changes when another variable changes?

guking

ADHDD&D
Veteran
Joined
Sep 11, 2018
Messages
82
Reaction score
34
First Language
Portuguese
Primarily Uses
RMMZ
Hey!

So, I'm making a system that every day a store gets a random supply demand, but I'm not really sure how to set up that.

The idea is: the player will choose which item he will go out and collect, so he will see what the store is lacking and set up a quest to go out and get it for the owner.

Day changes -> The store's demand changes -> player set a quest with those values and go get the items.

Can someone, please, help me with that?

P.S. Okay, as I'm typing it I see that changing the demand daily is a bad idea, but I can figure out a better way to trigger the change, maybe the demand will change the following day the player has finished the quest... well, I'll need to think on a better way to trigger the change, but that's not the point of this thread hehe :)
 

Metatoda42

I am most definitely, a Chuunibyou
Member
Joined
Jan 6, 2019
Messages
1
Reaction score
0
First Language
English
Primarily Uses
RMMZ
Try putting a check in the shop event (when the player opens the shop) and just add (daychangevar != supplyvar). If true, then the supply changes randomly.

Let me know if I misunderstood something, hope that helps!
 

Zerothedarklord

Veteran
Veteran
Joined
Jun 25, 2013
Messages
340
Reaction score
106
First Language
English
Primarily Uses
RMMV
set your second variable's value to be dependent upon the value of the first, and there you go, you have a variable that changes when another variable changes
 

guking

ADHDD&D
Veteran
Joined
Sep 11, 2018
Messages
82
Reaction score
34
First Language
Portuguese
Primarily Uses
RMMZ
set your second variable's value to be dependent upon the value of the first, and there you go, you have a variable that changes when another variable changes
sure. And I do that by...?
 

guking

ADHDD&D
Veteran
Joined
Sep 11, 2018
Messages
82
Reaction score
34
First Language
Portuguese
Primarily Uses
RMMZ
Hum, okay but I don't see how this helps me, it's just setting a variable to the same value of another variable. What I want is:

Every time Variable A gets +1, I want Variable B to give me a random number.
 

Shaz

Global Moderators
Global Mod
Joined
Mar 2, 2012
Messages
42,508
Reaction score
14,845
First Language
English
Primarily Uses
RMMV
You must have a Control Variables command to set the first variable. Do a Control Variables command to set the second variable to a random number at the same time.

Code:
Control Variables A += 1
Control Variables B = Random between 1 and 10

It's pretty straightforward and I'm not understanding where the difficulty is, so I'm wondering if there's some other requirement that isn't obvious in the way you've worded your request.
 

guking

ADHDD&D
Veteran
Joined
Sep 11, 2018
Messages
82
Reaction score
34
First Language
Portuguese
Primarily Uses
RMMZ
Oh, yeah, there was something I think I didn't specified in the original post: I need it to be different events.
 

Shaz

Global Moderators
Global Mod
Joined
Mar 2, 2012
Messages
42,508
Reaction score
14,845
First Language
English
Primarily Uses
RMMV
Then can you provide a more complete description? Why does it need to be in different events? What are they doing? At what point do you want the second variable to be changed?

Without knowing the above, I would say to turn on a switch when you change the first variable. At the point when you want the second variable to be changed, check if the switch is on - if it is, change the second variable and turn the switch off again. This could either be on the second event itself, or on a parallel process event on another map that does the check and then erases itself whether the switch was on or not.
 

guking

ADHDD&D
Veteran
Joined
Sep 11, 2018
Messages
82
Reaction score
34
First Language
Portuguese
Primarily Uses
RMMZ
Then can you provide a more complete description? Why does it need to be in different events? What are they doing? At what point do you want the second variable to be changed?

Without knowing the above, I would say to turn on a switch when you change the first variable. At the point when you want the second variable to be changed, check if the switch is on - if it is, change the second variable and turn the switch off again. This could either be on the second event itself, or on a parallel process event on another map that does the check and then erases itself whether the switch was on or not.

What I want is to be able to control how often variable A and B changes. If I condition B to change when A changes, I can't stop one from changing independently from the other.

If I create a switch (which I think would cause a loop, but I'm not sure) I could end messing it up with a lot of ons/offs.
The reason for this is:

Every day (var A) a new material demand (var B ) is available. There would be 25 different materials (var 1 ... 25). I want to be able to manipulate how often some may change and others don't without making lots of event commands. For the proof of concept of the game, it will only have 7 days and 10 materials, so I can do a big "if A == 1 else - if A == 2 .... if A == 7" But the idea of the game is being able to have a lot of days. Maybe material 1 and 2 have a higher demand on a Tuesday, maybe you have done something that will decrease demand for 13... And if you are on quest to gather 4 and 5, I want this demand to be +/- less frozen.

If I could set a trigger like "when A changes 3 times then B changes for 7 and 9" "when A == even B doesn't change" and etc etc... But, as far as I'm understanding, there's no way to reference to a "change" of a variable, just to its value, right?
 

guking

ADHDD&D
Veteran
Joined
Sep 11, 2018
Messages
82
Reaction score
34
First Language
Portuguese
Primarily Uses
RMMZ
Try putting a check in the shop event (when the player opens the shop) and just add (daychangevar != supplyvar). If true, then the supply changes randomly.

Let me know if I misunderstood something, hope that helps!
For some reason I haven't seen your reply.

Well, I understand nothing about JS or scripting, so I have no idea how to do that, sorry. :( I have not set up a shop event, I might just do a event per material, like the barrels where they are stored, to check the supply, since I have no idea how to make custom UIs
 

oriongates

Veteran
Veteran
Joined
Dec 26, 2019
Messages
219
Reaction score
59
First Language
english
Primarily Uses
RMMV
What I want is to be able to control how often variable A and B changes. If I condition B to change when A changes, I can't stop one from changing independently from the other.

If I create a switch (which I think would cause a loop, but I'm not sure) I could end messing it up with a lot of ons/offs.
The reason for this is:

Every day (var A) a new material demand (var B ) is available. There would be 25 different materials (var 1 ... 25). I want to be able to manipulate how often some may change and others don't without making lots of event commands. For the proof of concept of the game, it will only have 7 days and 10 materials, so I can do a big "if A == 1 else - if A == 2 .... if A == 7" But the idea of the game is being able to have a lot of days. Maybe material 1 and 2 have a higher demand on a Tuesday, maybe you have done something that will decrease demand for 13... And if you are on quest to gather 4 and 5, I want this demand to be +/- less frozen.

If I could set a trigger like "when A changes 3 times then B changes for 7 and 9" "when A == even B doesn't change" and etc etc... But, as far as I'm understanding, there's no way to reference to a "change" of a variable, just to its value, right?

I don't think you can implement a system like what you're describing without a lot of switches and variables being involved.

Essentially, each condition you want will have to be indicated through a combination of switches, variables or items and if I understand what you're trying to do it's not going to be something doable without a lot of work.

So, for instance. If you want your first trigger "when A changes 3 times then B changes..." then you would need to have whatever Event changes variable A increment variable C by one. Variable B's event can have a conditional branch which says "if variable C = 3" that then initiates the desired changes to Variable B. Then it could either reset variable C, or allow it to keep incrementing if something is going to happen later.

For your second one, the only way I can think of to determine if a number is even or odd is to flip a switch every time it increments. So, Variable A starts at 0 and Switch D starts "off." When the event adds +1 to variable A it has a conditional branch which checks if Switch D is off, and if it is then it switches to on and an 'else' branch that flips the switch off it is on. That means whenever Switch D is off then you know variable A is "even" and whenever it is on you know Variable A is odd, and can incorporate it into your conditional branch.


Honestly, though, it seems like at that point it would be easier for you to jut map out a calendar yourself and create simple, conditional branches.

So, Day 1, Variable A =1.
Conditional Branch that says if Variable A =1 then the current demand is [item X] (or choose randomly from a small chart generated by a second variable that can be reused on other days).

Another conditional branch for variable A =2, 3, 4, etc.

Just literally make a calender to reference so you know whether day 5 is a tuesday or whatever and just have small conditional branches that trigger consecutively each day. You could even loop it to last longer and maybe include nested conditions which adjust things based on player level or current supplies.
 

Trihan

Speedy Scripter
Veteran
Joined
Apr 12, 2012
Messages
3,453
Reaction score
2,573
First Language
English
Primarily Uses
RMMZ
You could do this with a parallel process common event. Set aside a variable for "how many times A needs to change before B does", create a common event that checks A's value and then if your set-aside variable is 0 change the value of B to a random number and set your set-aside variable back to its initial value, otherwise decrement it. Then when your game begins, set your set-aside variable to whatever its initial value should be. Note that you'll also need an activation switch for the event that you'll have to turn on at the start.
 

guking

ADHDD&D
Veteran
Joined
Sep 11, 2018
Messages
82
Reaction score
34
First Language
Portuguese
Primarily Uses
RMMZ
I don't think you can implement a system like what you're describing without a lot of switches and variables being involved.

Essentially, each condition you want will have to be indicated through a combination of switches, variables or items and if I understand what you're trying to do it's not going to be something doable without a lot of work.

So, for instance. If you want your first trigger "when A changes 3 times then B changes..." then you would need to have whatever Event changes variable A increment variable C by one. Variable B's event can have a conditional branch which says "if variable C = 3" that then initiates the desired changes to Variable B. Then it could either reset variable C, or allow it to keep incrementing if something is going to happen later.

For your second one, the only way I can think of to determine if a number is even or odd is to flip a switch every time it increments. So, Variable A starts at 0 and Switch D starts "off." When the event adds +1 to variable A it has a conditional branch which checks if Switch D is off, and if it is then it switches to on and an 'else' branch that flips the switch off it is on. That means whenever Switch D is off then you know variable A is "even" and whenever it is on you know Variable A is odd, and can incorporate it into your conditional branch.


Honestly, though, it seems like at that point it would be easier for you to jut map out a calendar yourself and create simple, conditional branches.

So, Day 1, Variable A =1.
Conditional Branch that says if Variable A =1 then the current demand is [item X] (or choose randomly from a small chart generated by a second variable that can be reused on other days).

Another conditional branch for variable A =2, 3, 4, etc.

Just literally make a calender to reference so you know whether day 5 is a tuesday or whatever and just have small conditional branches that trigger consecutively each day. You could even loop it to last longer and maybe include nested conditions which adjust things based on player level or current supplies.
Well, I wanted a easier way to control all of that. as I see, you can't condition something to a change of a variable just to it's number. Adding switches to the mix may lead to confusing when dealing with the events, but I think that's what I'll have to do. Or I will just implement a less elegant way to achieve what I want. Because my idea wasn't to have it "set to stone" which days do what, but it would be random and different each playthrough.

Well, I'll see what I can do if I come up with anything I'll let you guys know. I wish the maker had a visual way to show how variables, switches, conditions and etc etc are interacting.
 

oriongates

Veteran
Veteran
Joined
Dec 26, 2019
Messages
219
Reaction score
59
First Language
english
Primarily Uses
RMMV
Well, I wanted a easier way to control all of that. as I see, you can't condition something to a change of a variable just to it's number. Adding switches to the mix may lead to confusing when dealing with the events, but I think that's what I'll have to do. Or I will just implement a less elegant way to achieve what I want. Because my idea wasn't to have it "set to stone" which days do what, but it would be random and different each playthrough.

Well, I'll see what I can do if I come up with anything I'll let you guys know. I wish the maker had a visual way to show how variables, switches, conditions and etc etc are interacting.

I will say that I think you can hit an achievable level of randomness through the use of a calendar. Nothing is stopping you from have a table of 20 or 30 or 50 random possibilities each day and maybe even conditions that only occur if the player has done X or Y and you can easily change up that list of random possibilities so different days are more likely to require one thing or another. You could even mix things up and have the starting variable be randomized to start players at different parts of the calendar on different playthroughs.

My main point is that you're looking at something that is incredibly easy for a human to work out, but a significant challenge to "teach" a program to do from first principles.

To give an example, it'd take a human almost no effort to mark the first tuesday of every month on a calendar and only slightly more effort to do the math and figure out what day out of 365 that corresponds to (if you simplify things to a 28 or 30 day calendar its even easier).

But teaching RPG maker to identify the first tuesday of every month through a combination of switches and variables is *not* an easy task.

This is just one of those cases where automation (at least automation with the tools you have available) is actually more effort, not less.
 

guking

ADHDD&D
Veteran
Joined
Sep 11, 2018
Messages
82
Reaction score
34
First Language
Portuguese
Primarily Uses
RMMZ
I will say that I think you can hit an achievable level of randomness through the use of a calendar. Nothing is stopping you from have a table of 20 or 30 or 50 random possibilities each day and maybe even conditions that only occur if the player has done X or Y and you can easily change up that list of random possibilities so different days are more likely to require one thing or another. You could even mix things up and have the starting variable be randomized to start players at different parts of the calendar on different playthroughs.

My main point is that you're looking at something that is incredibly easy for a human to work out, but a significant challenge to "teach" a program to do from first principles.

To give an example, it'd take a human almost no effort to mark the first tuesday of every month on a calendar and only slightly more effort to do the math and figure out what day out of 365 that corresponds to (if you simplify things to a 28 or 30 day calendar its even easier).

But teaching RPG maker to identify the first tuesday of every month through a combination of switches and variables is *not* an easy task.

This is just one of those cases where automation (at least automation with the tools you have available) is actually more effort, not less.
Well, that's the thing. I don't want a SET amount of possibilities. I want it to be random. But I'll try to figure something then, thanks!
 

Bex

Veteran
Veteran
Joined
Aug 2, 2013
Messages
1,502
Reaction score
412
First Language
German
Primarily Uses
RMMV
as I see, you can't condition something to a change of a variable just to it's number.
My English aint the best, but i believe it is possible.
We just need 1 extra Variable to help us detect the change. Because we need to know the value it has now, and the previous value of that variable, than we can determine if it changed or not.

This code would be true and be executed once every Day:
◆Control Variables:#0001 Var1 Total Days = Total Days
◆If:Var1 Total Days > Var2 This Day
◆Control Variables:#0002 Var2 This Day = Var1 Total Days
◆Control Variables:#0003 Var3 Shop Demand = Random 1..25

:End

This code would be true and be executed once every 2 Days:
◆Control Variables:#0001 Var1 Total Days = Total Days
◆If:Var1 Total Days > Var2 This Day
◆Control Variables:#0002 Var2 This Day = Var1 Total Days
◆Control Variables:#0002 Var2 This Day += 1
◆Control Variables:#0003 Var3 Shop Demand = Random 1..25

:End

Depending on the kind of Time System this would be implemented differently or would need some edits or adjustments. Not sure if i understood the problerm correctly.
 
Last edited:

Latest Threads

Latest Posts

Latest Profile Posts

Quite the versatile cast so far :p

chars.PNG

Edit: Sprites are made by Alexdraws and TheMightyPalm. I just edited them.
Degica Games Turn Komodo | RPG Maker News #77

Well, rats. Was really looking forward to trying out FPS Creator, but trying to install and set it up was pretty much impossible for my tiny brain to comprehend. So much for that, then.
Ah, home once more! I think I can safely work on my games now.
Let's hope power remains on for the day

Forum statistics

Threads
112,406
Messages
1,068,099
Members
146,058
Latest member
jon787
Top