Cutstuff Forum

Mega Man 8-bit Deathmatch => Help & Editing => Topic started by: Hilman170499 on August 31, 2017, 05:18:23 AM

Title: Carry-over variables
Post by: Hilman170499 on August 31, 2017, 05:18:23 AM
Anyone here happen to know how to make variables with values that carry over in spite of playing a different map/round? In case anyone brings it up, I tried using global/world variables, but when applied to player numbers, it can glitch out. I ask if anyone knows an effective alternative. Thanks in advance.
Title: Re: Carry-over variables
Post by: CutmanMike on August 31, 2017, 12:02:27 PM
They should work fine. Would probably better if you explain what you're trying to do with them?
Title: Re: Carry-over variables
Post by: Hilman170499 on August 31, 2017, 01:18:54 PM
Alright, so with the global variables, I'm trying to devise a system where it would randomly choose a player. Then, the player data is saved into a variable, in which the value is carried over to the next map/round. This is to prevent the system from choosing the same player twice in a row.
However, the problem I am facing is that somehow, the system outright refuses to choose the first player to join the game, no matter how many rounds I played.
Title: Re: Carry-over variables
Post by: CutmanMike on August 31, 2017, 02:08:35 PM
After the match/round if you PrintBold the global variable, does it give you the expected result? Either way probably best if you show me the code.
Title: Re: Carry-over variables
Post by: Hilman170499 on August 31, 2017, 06:24:06 PM
Alright, here is a simplified version of the scripting I extracted.
Code: [Select]
int whoisboss;

global int 60:bossprev;

script 702 OPEN
{
whoisboss = random(0, PlayerCount());
while(whoisboss == bossprev||!PlayerInGame(whoisboss)){whoisboss = random(0, PlayerCount());}
bossprev = whoisboss;
}
Title: Re: Carry-over variables
Post by: CutmanMike on August 31, 2017, 06:38:31 PM
First of all, this won't work correctly because the default global int value is 0, which will trigger the whoisboss == bossprev loop if it lands on the first player (player 0). A simple workaround would be do +1 when reading and writing the boss value. That way you can use 0 as "No boss assigned".

Second, drop a PrintBold(s:"whoisboss is ", i:whoisboss, s:" and bossprev is ", i:bossprev); at the end of this script to see what is being assigned. Finally do a Delay(1); at the very start of the script. Usually not required but sometimes that can trip some scripts up when working online.
Title: Re: Carry-over variables
Post by: Hilman170499 on August 31, 2017, 07:02:07 PM
Quote
A simple workaround would be do +1 when reading and writing the boss value. That way you can use 0 as "No boss assigned".

Can you please clarify this? As in, where exactly should I do this?
Title: Re: Carry-over variables
Post by: CutmanMike on August 31, 2017, 07:20:18 PM
Do +1 when setting a new whoisboss:

Code: [Select]
whoisboss = random(0, PlayerCount()) + 1;
You didn't specify where you will be reading this value, I assume it will be to do something to players. In this example I'll just deal 50 damage to whoever the boss is:

Code: [Select]
Thing_Damage(whoisboss + 1000 - 1,  50, 0)
If we didn't do -1 it would be using the incorrect number because we did +1 earlier. If you need more clarity DM me on discord as I can probably help quicker there.
Title: Re: Carry-over variables
Post by: Hilman170499 on September 01, 2017, 03:54:51 AM
Alright. This actually works now that I know this. Thanks.