Advanced Search

Author Topic: Carry-over variables  (Read 2361 times)

0 Members and 1 Guest are viewing this topic.

August 31, 2017, 05:18:23 AM
Read 2361 times

Offline Hilman170499

  • MM8BDM Extender

  • BLUE FOR DAYS!!!
  • **
  • Date Registered: March 18, 2012, 05:49:26 AM

    • View Profile
Carry-over variables
« 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.

August 31, 2017, 12:02:27 PM
Reply #1

Offline CutmanMike

  • Administrator

  • Is it hot in here or is it just zscript?
  • *******
  • Date Registered: December 17, 2008, 12:24:34 PM

    • View Profile
    • https://cutstuff.net
Re: Carry-over variables
« Reply #1 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?

August 31, 2017, 01:18:54 PM
Reply #2

Offline Hilman170499

  • MM8BDM Extender

  • BLUE FOR DAYS!!!
  • **
  • Date Registered: March 18, 2012, 05:49:26 AM

    • View Profile
Re: Carry-over variables
« Reply #2 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.

August 31, 2017, 02:08:35 PM
Reply #3

Offline CutmanMike

  • Administrator

  • Is it hot in here or is it just zscript?
  • *******
  • Date Registered: December 17, 2008, 12:24:34 PM

    • View Profile
    • https://cutstuff.net
Re: Carry-over variables
« Reply #3 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.

August 31, 2017, 06:24:06 PM
Reply #4

Offline Hilman170499

  • MM8BDM Extender

  • BLUE FOR DAYS!!!
  • **
  • Date Registered: March 18, 2012, 05:49:26 AM

    • View Profile
Re: Carry-over variables
« Reply #4 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;
}

August 31, 2017, 06:38:31 PM
Reply #5

Offline CutmanMike

  • Administrator

  • Is it hot in here or is it just zscript?
  • *******
  • Date Registered: December 17, 2008, 12:24:34 PM

    • View Profile
    • https://cutstuff.net
Re: Carry-over variables
« Reply #5 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.

August 31, 2017, 07:02:07 PM
Reply #6

Offline Hilman170499

  • MM8BDM Extender

  • BLUE FOR DAYS!!!
  • **
  • Date Registered: March 18, 2012, 05:49:26 AM

    • View Profile
Re: Carry-over variables
« Reply #6 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?

August 31, 2017, 07:20:18 PM
Reply #7

Offline CutmanMike

  • Administrator

  • Is it hot in here or is it just zscript?
  • *******
  • Date Registered: December 17, 2008, 12:24:34 PM

    • View Profile
    • https://cutstuff.net
Re: Carry-over variables
« Reply #7 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.

September 01, 2017, 03:54:51 AM
Reply #8

Offline Hilman170499

  • MM8BDM Extender

  • BLUE FOR DAYS!!!
  • **
  • Date Registered: March 18, 2012, 05:49:26 AM

    • View Profile
Re: Carry-over variables
« Reply #8 on: September 01, 2017, 03:54:51 AM »
Alright. This actually works now that I know this. Thanks.