ENGLESNELLGROVE'S PROFILE
Search
Using a variable as multiple switches.
I just wrote this up for my blog. I thought it might be useful for others to read it; and it would certainly be useful for me to see any comments or corrections. Give it a read if you have the time. (By the way, I'm a completely untrained programmer. I assume this stuff is pretty basic, but it's completely new to me.)
---
I am working within a branching conversation. You are talking with a character, and their responses change depending on what you say or do. Certain responses from the character lead toward a particular conclusion to the conversation. Once you have received these certain responses, the conversation ends.
I'll make this example more concrete:
Say you are a detective, and you are interrogating a suspect. You want to discover three holes in the suspect's alibi. Once you discover three holes, you know you will be able to convict the suspect.
So, when you are programming this hypothetical interrogation in RPG Maker 2003, you need to indicate to the program a) when a hole in the alibi is discovered and b) when three holes have been discovered.
You might simply create a counter (a variable) that increases whenever a hole is discovered. When the counter hits three, the conversation ends, and you've got your suspect. However, unless you ensure that the player doesn't ask the same question twice (and rediscover the same hole in the alibi), the counter will increase whenever any given hole is discovered or rediscovered. So the player could simply ask the same question three times, the game will assume he's found all the holes, and the conversation will end.
You can solve this problem by turning each hole into a switch. Then, instead of counting up to three and ending the conversation, the program turns on three different switches. When all three have turned on, make the conversation end.
I've programmed certain parts of "Aniktophlox" like this, and I find myself with lots and lots of switches! Today I discovered a better, more code-efficient way to do this.
I started thinking about the problem like this: instead of using a variable as a counter, maybe it could be used as a collection of switches. The easiest way to imagine this was to imagine a variable in which each digit is a switch: 001 (or 1) would mean the third switch is on; 010 would mean the second switch is on; 110 would mean the first two switches are on; and so on. But this didn't work, because I couldn't get RPG Maker 2003 to check those digits in the way I imagined. I tried using division and modulus operations, but nothing worked out.
Somehow, I hit on the idea of using prime numbers. I didn't know how I would use prime numbers, but I realized I could think of the problem like this: 2 contains 1 and 2; 3 contains 1 and 3, but not 2; 5 contains 1 and 5, but not three; and so on. I felt as though I was on the right track. I tried throwing a few non-prime numbers into the mix, but that idea didn't pan out. Eventually I decided that I needed to work with bigger numbers, so I took 3, 5, and 7 -- three primes -- and started multiplying them together:
3x3=9,
3x5=15,
3x7=21,
5x5=25,
5x7=35,
and so on...
I wrote down all these multiplication products and started dividing each one by 3, by 5, and by 7; then I looked at which multiples left remainders. {In RPG Maker 2003, you can manipulate a variable in this way: divide it by a given number and then change the original variable into what remains after the division. In my fantasy, I could somehow do this operation and then check if the variable had become a zero (0 = a switch turned off, in my original idea) or not (1 = a switch turned on, in my original idea).} So I started getting these numbers:
35
divided by 3 leaves a remainder of 2 ("3" is "on");
divided by 5 leaves no remainder ("5" is "off");
divided by 7 leaves no remainder ("7" is "off").
As I went through all my multiplication products, I eventually found all the various combinations of my three imagined switches being either off or on. I was amazed! But I had gone so far from my original conception of each digit as an imaginary switch (001, 010, 100, and so on) that I didn't know how to implement what I'd found. I thought a while, feeling very confused but very sure that I was figuring something out. Ultimately, I set up my version of the interrogation program like this:
I first set the variable to 1. This is my imaginary, multi-switch variable. At 1, every switch is off. Each imaginary switch is a prime number; and to turn a switch on, you simply multiply the variable by that prime number: e.g., 1x3=3. Now, if you check the variable (set to 3) by dividing by any given switch (i.e., prime number), here's what you get:
3
divided by 3 leaves no remainder ("3" is "off");
divided by 5 leaves a remainder ("5" is "on");
divided by 7 leaves a remainder ("7" is "on").
This is the opposite of how I want it! The imaginary 3 switch was suppsed to be on, not off! But this is easily remedied: instead of programming a remainder as an "on," program it as an "off!" Thus:
3
divided by 3 leaves no remainder ("3" is "on");
divided by 5 leaves a remainder ("5" is "off");
divided by 7 leaves a remainder ("7" is "off").
Let's bring this idea back to our interrogation program. The player is interrogating a suspect and wants to find three holes in the suspect's alibi. We will label each hole as a prime number. Whenever the player discovers a hole, we multiply our "multi-switch" variable (first set to 1) by that hole's prime number. But also, before that, to be certain the hole hasn't already been discovered, we first check to see if division by that hole's prime number returns a remainder or not. If a remainder isn't found, the imaginary switch has already been turned on and we don't need to turn it on again.
So, instead of having three separate switches for these three holes in the alibi, we can now check them all with one variable.
E/S
---
I am working within a branching conversation. You are talking with a character, and their responses change depending on what you say or do. Certain responses from the character lead toward a particular conclusion to the conversation. Once you have received these certain responses, the conversation ends.
I'll make this example more concrete:
Say you are a detective, and you are interrogating a suspect. You want to discover three holes in the suspect's alibi. Once you discover three holes, you know you will be able to convict the suspect.
So, when you are programming this hypothetical interrogation in RPG Maker 2003, you need to indicate to the program a) when a hole in the alibi is discovered and b) when three holes have been discovered.
You might simply create a counter (a variable) that increases whenever a hole is discovered. When the counter hits three, the conversation ends, and you've got your suspect. However, unless you ensure that the player doesn't ask the same question twice (and rediscover the same hole in the alibi), the counter will increase whenever any given hole is discovered or rediscovered. So the player could simply ask the same question three times, the game will assume he's found all the holes, and the conversation will end.
You can solve this problem by turning each hole into a switch. Then, instead of counting up to three and ending the conversation, the program turns on three different switches. When all three have turned on, make the conversation end.
I've programmed certain parts of "Aniktophlox" like this, and I find myself with lots and lots of switches! Today I discovered a better, more code-efficient way to do this.
I started thinking about the problem like this: instead of using a variable as a counter, maybe it could be used as a collection of switches. The easiest way to imagine this was to imagine a variable in which each digit is a switch: 001 (or 1) would mean the third switch is on; 010 would mean the second switch is on; 110 would mean the first two switches are on; and so on. But this didn't work, because I couldn't get RPG Maker 2003 to check those digits in the way I imagined. I tried using division and modulus operations, but nothing worked out.
Somehow, I hit on the idea of using prime numbers. I didn't know how I would use prime numbers, but I realized I could think of the problem like this: 2 contains 1 and 2; 3 contains 1 and 3, but not 2; 5 contains 1 and 5, but not three; and so on. I felt as though I was on the right track. I tried throwing a few non-prime numbers into the mix, but that idea didn't pan out. Eventually I decided that I needed to work with bigger numbers, so I took 3, 5, and 7 -- three primes -- and started multiplying them together:
3x3=9,
3x5=15,
3x7=21,
5x5=25,
5x7=35,
and so on...
I wrote down all these multiplication products and started dividing each one by 3, by 5, and by 7; then I looked at which multiples left remainders. {In RPG Maker 2003, you can manipulate a variable in this way: divide it by a given number and then change the original variable into what remains after the division. In my fantasy, I could somehow do this operation and then check if the variable had become a zero (0 = a switch turned off, in my original idea) or not (1 = a switch turned on, in my original idea).} So I started getting these numbers:
35
divided by 3 leaves a remainder of 2 ("3" is "on");
divided by 5 leaves no remainder ("5" is "off");
divided by 7 leaves no remainder ("7" is "off").
As I went through all my multiplication products, I eventually found all the various combinations of my three imagined switches being either off or on. I was amazed! But I had gone so far from my original conception of each digit as an imaginary switch (001, 010, 100, and so on) that I didn't know how to implement what I'd found. I thought a while, feeling very confused but very sure that I was figuring something out. Ultimately, I set up my version of the interrogation program like this:
I first set the variable to 1. This is my imaginary, multi-switch variable. At 1, every switch is off. Each imaginary switch is a prime number; and to turn a switch on, you simply multiply the variable by that prime number: e.g., 1x3=3. Now, if you check the variable (set to 3) by dividing by any given switch (i.e., prime number), here's what you get:
3
divided by 3 leaves no remainder ("3" is "off");
divided by 5 leaves a remainder ("5" is "on");
divided by 7 leaves a remainder ("7" is "on").
This is the opposite of how I want it! The imaginary 3 switch was suppsed to be on, not off! But this is easily remedied: instead of programming a remainder as an "on," program it as an "off!" Thus:
3
divided by 3 leaves no remainder ("3" is "on");
divided by 5 leaves a remainder ("5" is "off");
divided by 7 leaves a remainder ("7" is "off").
Let's bring this idea back to our interrogation program. The player is interrogating a suspect and wants to find three holes in the suspect's alibi. We will label each hole as a prime number. Whenever the player discovers a hole, we multiply our "multi-switch" variable (first set to 1) by that hole's prime number. But also, before that, to be certain the hole hasn't already been discovered, we first check to see if division by that hole's prime number returns a remainder or not. If a remainder isn't found, the imaginary switch has already been turned on and we don't need to turn it on again.
So, instead of having three separate switches for these three holes in the alibi, we can now check them all with one variable.
E/S
HELP: RM2k3 executes battle command that was cancelled.
This glitch must be known. I came across it in Calunio's Polymorphous Perversity. I'll explain how it's manifesting in my game:
During a battle sequence, I select the "Use Item" battle command. This takes me to the Items submenu. I cancel out of this, then select a "Link to Event"-style battle command. Once the "Link to Event" command executes, RM2k3 apparently tries to execute the cancelled "Use Item" command. Whatever happens, I get an error -- "Event script referenced an item that does not exist" -- and then the game crashes. ((In Polymorphous Perversity, I remember the bug didn't crash the game; but it did cause the player to execute two battle commands in one turn, the one unintentional. So I suppose the same is happening in my game.)) I've scoured every referenced script for non-existent items, but I've found nothing amiss. I get this glitch whether the "Use Item" menu contains no items, unusable items, or useful items. The game always crashes.
What gives? Anybody seen this? Anybody solved this?
Thanks.
E/S
During a battle sequence, I select the "Use Item" battle command. This takes me to the Items submenu. I cancel out of this, then select a "Link to Event"-style battle command. Once the "Link to Event" command executes, RM2k3 apparently tries to execute the cancelled "Use Item" command. Whatever happens, I get an error -- "Event script referenced an item that does not exist" -- and then the game crashes. ((In Polymorphous Perversity, I remember the bug didn't crash the game; but it did cause the player to execute two battle commands in one turn, the one unintentional. So I suppose the same is happening in my game.)) I've scoured every referenced script for non-existent items, but I've found nothing amiss. I get this glitch whether the "Use Item" menu contains no items, unusable items, or useful items. The game always crashes.
What gives? Anybody seen this? Anybody solved this?
Thanks.
E/S
SOLVED: Switch-type Item Activation Problem
I wrote this little problem solution for future reference and posted it to my blog. I didn't find the same solution on these forums, so I decided to post it here, too. Maybe it will help someone, or maybe someone will have further information about the issue.
E/S
PROBLEM:
I have a "Switch"-type item, Rock Innards, which are currently usable only on the map screens. The player should be able to use the Rock Innards during a battle. So, on the Item screen, I checked the box to allow item activation during battle. However, when I tested this, the item remained unavailable during battle.
SOLUTION:
RM2k3 allows various types of items. Rock Innards are a "Switch"-type item. This item type is not, apparently, useful only to certain characters. By comparison, a "Skill Scroll" item can only be used by certain characters, and RM2k3 asks you to designate which characters on the item screen for such an item. It doesn't ask you this for a "Switch" item. However, for a "Switch" item, RM2k3 is secretly carrying over the "Usable By" information from the item screen that would appear if that "Switch" item were, say, a "Skill Scroll" item. So, in order to make my Rock Innards usable during battle, I not only had to check the "Battle" activation box, I also had to temporarily set my item as a "Skill Scroll" item (or a "Seed" item or any other with a "Usable By" setting) and check that my hero ("Tom Wilson") can use the item; then I set the item back to a "Switch"-type item. This solved the problem.
E/S
PROBLEM:
I have a "Switch"-type item, Rock Innards, which are currently usable only on the map screens. The player should be able to use the Rock Innards during a battle. So, on the Item screen, I checked the box to allow item activation during battle. However, when I tested this, the item remained unavailable during battle.
SOLUTION:
RM2k3 allows various types of items. Rock Innards are a "Switch"-type item. This item type is not, apparently, useful only to certain characters. By comparison, a "Skill Scroll" item can only be used by certain characters, and RM2k3 asks you to designate which characters on the item screen for such an item. It doesn't ask you this for a "Switch" item. However, for a "Switch" item, RM2k3 is secretly carrying over the "Usable By" information from the item screen that would appear if that "Switch" item were, say, a "Skill Scroll" item. So, in order to make my Rock Innards usable during battle, I not only had to check the "Battle" activation box, I also had to temporarily set my item as a "Skill Scroll" item (or a "Seed" item or any other with a "Usable By" setting) and check that my hero ("Tom Wilson") can use the item; then I set the item back to a "Switch"-type item. This solved the problem.
Help: Event stops executing after "Recall to Location."
I'm programming a mini-game within my game. If the player loses the minigame by shooting the wrong object (two X & Y variables match up), an event is called which shows a picture, recalls the hero back to the location memorized before the mini-game began, and should then execute some other commands to reset a few switches and variables. But, instead, the event mysteriously stops executing after the "Recall to Memorized Position" command. ((Actually, even more mysteriously, the event stops if the following command is a "Message" command; but it doesn't stop if the following command is a "Change Sprite Assocation" command, in which case it stops after changing the sprite.)) In effect, this means that the variables are not reset because those commands don't execute.
I'm totally puzzled. Any help would be appreciated. I can send game files if necessary.
E/S
I'm totally puzzled. Any help would be appreciated. I can send game files if necessary.
E/S
I'm slowly working on a RM2k3 game.
I've been building an RPG Maker game, on and off, for the past year or so. I'm about 25% done, maybe less. I'm using custom sprites and sounds. The game takes place in a small dystopian totalitarian community, and the player follows the rules of that community (or not) while discovering the overall workings and secrets of the place. And other stuff happens.
Anyhow, I've put a lot of work into the project, and I'd like lots of people to play it. I also want lots of people to test it out and write me responses to the game ... because I'm finding it is very easy to get overwhelmed by all the tasks of game design and coding. I need some smart gamers to help out!
I thought I'd introduce myself here and take a small step into this online community, to see how things go here. I've browsed the forum before and found some help when coding parts of my game.
Here's a development blog that I recently began:
http://idiotarchetype.blogspot.com/
The game is called "Aniktophlox," at least for now.
Thanks for reading,
E/S
Anyhow, I've put a lot of work into the project, and I'd like lots of people to play it. I also want lots of people to test it out and write me responses to the game ... because I'm finding it is very easy to get overwhelmed by all the tasks of game design and coding. I need some smart gamers to help out!
I thought I'd introduce myself here and take a small step into this online community, to see how things go here. I've browsed the forum before and found some help when coding parts of my game.
Here's a development blog that I recently began:
http://idiotarchetype.blogspot.com/
The game is called "Aniktophlox," at least for now.
Thanks for reading,
E/S
Pages:
1













