Cutstuff Forum
Mega Man 8-bit Deathmatch => Help & Editing => Topic started 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.
-
They should work fine. Would probably better if you explain what you're trying to do with them?
-
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.
-
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.
-
Alright, here is a simplified version of the scripting I extracted.
int whoisboss;
global int 60:bossprev;
script 702 OPEN
{
whoisboss = random(0, PlayerCount());
while(whoisboss == bossprev||!PlayerInGame(whoisboss)){whoisboss = random(0, PlayerCount());}
bossprev = whoisboss;
}
-
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.
-
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?
-
Do +1 when setting a new whoisboss:
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:
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.
-
Alright. This actually works now that I know this. Thanks.