• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Legacy GM Variables misbehaving!

Focksbot

Member
I'm trying to set up a queueing system for scrolling text, so that as events in the game generate a text commentary, each new chunk generated waits patiently for its turn to scroll.

I have the variables 'queueing', which denotes the number of chunks of text currently in the queue, and 'queue' which denotes how far back the queue goes. In the code below, I'm trying to get it so that as each chunk of text leaves the screen it tells 'queueing' to reduce, and that once 'queueing' is back down to 0 (ie. there is no queue), the length of the queue is also reset.

Code:

//Reduces the number queueing by 1 as it exits the screen//
if x = 0 and once = 0 and global.queueing > 0 {
once = 1
global.queueing -= 1
}

//Resets the queue to 0 as it leaves the screen *if* there is no queue//
if x = 0 and once = 0 and global.queueing = 0 {
once = 1
global.queue = 0
}​

I've set it up so that both these variables are displayed on my screen for trouble-shooting. What I'm finding is that as a chunk of text goes off screen (x = 0) it will reduce both 'queueing' and 'queue' from any number to 0 instantaneously.

Note that I've added the variable 'once' to try to make sure that the event can only trigger once per text chunk.

Any idea why this is happening? 'queueing' should be going down by 1 each time, not jumping straight from 2 or 3 to 0, and 'queue' should only reduce to 0 once 'queueing' is already at 0.

Thanks in advance for your time.
 

Phil Strahl

Member
First: Have you considered using a ds_queue data structure to store your text in? Because it offers some nice functionality to push and pop entries.

Then: I tried to understand what exactly your text/code is doing but I couldn't wrap my head around it. Maybe refactoring your queue would make things easier. This is how I would do it:
  • Have an object for displaying each line of text, e.g. obj_message that holds a string.
  • Have a global ds_queue (or better: a queue controller object with a ds_queue) to which each time when a message should gets displayed, an the id of an obj_message instance gets added, something like this
Code:
var message = instance_create(1920,960,obj_message); // creates a new instance
message.content = "All your base are belong to us!"; // sets the content variable in the obj_message which it should display when active
message.active = false; // sets the active variable to false, which could make the text invisible until it is set to "active"
ds_queue_enqueue(global.messageQueue, message); // stores the id of the current message
  • When the ds_queue is not empty, the first instance of obj_message gets notified to become active and processing the queue is set on hold
  • When the obj_message has scrolled off screen, it notifies the queue_controller that it has finished and kills itself
  • the queue controller gets the next obj_message instance and, again, holds processing the queue until it gets notice
  • etc.
Granted, that seems a bit complicated and requires some work but it's much easier to maintain and modify. E.g. your queue controller doesn't care how the messages are displayed, all it does is set each of them to "active" and waits until is should enqueue the next item. The obj_message does not need to know about the queue, all it needs to know is when to do when set to "active" and when to notify the queue controller that it's finished.

Hope that helps.
 
Top