Initiative list for RPG
Started by sournote103, Jun 16 2012 08:33 PM
12 replies to this topic
#1
Posted 16 June 2012 - 08:33 PM
I am trying to program an RPG, and I am slightly stuck on how to tell the game in what order the players and enemies should act in battle.
The character with the highest speed stat acts first (each player character and enemy has a speed stat stored to a variable).
I seems to me that using a ds_list or ds_queue would be the best way to do this, but I am unsure of how to do this and still keep every speed stat attributed to the correct character. How would I do this?
The character with the highest speed stat acts first (each player character and enemy has a speed stat stored to a variable).
I seems to me that using a ds_list or ds_queue would be the best way to do this, but I am unsure of how to do this and still keep every speed stat attributed to the correct character. How would I do this?
#2
Posted 16 June 2012 - 08:38 PM
A priority queue seems appropriate for this purpose. Every time you need to go through the order, I would fill the queue with speed/id pairs for each instance involved in the battle, and the pop the lowest values out to determine the order.
#3
Posted 16 June 2012 - 08:53 PM
I've implemented that, but now it's giving me an error saying that "Data structure with index does not exist."
What does this mean? I have tried searching online, but have not found any information on this particular error.
What does this mean? I have tried searching online, but have not found any information on this particular error.
#4
Posted 16 June 2012 - 09:00 PM
That error means that you tried to access a priority queue using a value that wasn't the index of any existing queue. Without seeing the code that you used, it's difficult to give any suggestions for fixing the error - one common cause, though, is improper argument order. Your code should look something like this:
var queue; queue = ds_priority_create(); ds_priority_add(queue, "first", 0); ds_priority_add(queue, "third", 2); ds_priority_add(queue, "second", 1); show_message(ds_priority_delete_min(queue)); // first show_message(ds_priority_delete_min(queue)); // second show_message(ds_priority_delete_min(queue)); // third
#5
Posted 16 June 2012 - 09:22 PM
I had it set up just like that, yet it is still giving me the same error.
#6
Posted 16 June 2012 - 11:47 PM
Could we see the code that you used?
#7
Posted 17 June 2012 - 02:09 AM
I have messed around with it a fair bit, but I can likely revert it to how I had it when I have a bit more time.
#8
Posted 17 June 2012 - 02:14 AM
OK, actually, I have the code commented out, so here it is:
var initiative;
initiative = ds_priority_create()
if instance_exists(obj_enemy1)
{ds_priority_add(initiative,obj_enemy1,obj_enemy1.spd)}
if instance_exists(obj_enemy2)
{ds_priority_add(initiative,obj_enemy2,obj_enemy2.spd)}
if instance_exists(obj_enemy3)
{ds_priority_add(initiative,obj_enemy3,obj_enemy3.spd)}
if instance_exists(obj_enemy4)
{ds_priority_add(initiative,obj_enemy4,obj_enemy4.spd)}
if instance_exists(obj_player1)
{ds_priority_add(initiative,obj_player1,obj_player1.spd)}
if instance_exists(obj_player2)
{ds_priority_add(initiative,obj_player2,obj_player2.spd)}
if instance_exists(obj_player3)
{ds_priority_add(initiative,obj_player3,obj_player3.spd)}
if instance_exists(obj_player4)
{ds_priority_add(initiative,obj_player4,obj_player4.spd)}"spd" is the variable in which each character's speed stat is stored.
#9
Posted 17 June 2012 - 09:22 AM
one reason you could be getting errors would be if you tried to access initiative outside this script, since you have made it a "var" variable (meaning that the variable will not exists after the code block ends)
#10
Posted 17 June 2012 - 12:37 PM
Hm... That would be a problem. But nevertheless, I get the same error even without the "var" there.
#11
Posted 17 June 2012 - 12:58 PM
can't see anything else that is wrong with the current code, and you have not told us if the error is in that code, if not then it would be better if you could post the code with the error aswell, and what events/object the currently posted and the error one are in..
if they are in the same event then it could be the event order that is wrong, so you will have to change the depth of the controller to a lower number so make it perform its event first
if they are in the same event then it could be the event order that is wrong, so you will have to change the depth of the controller to a lower number so make it perform its event first
#12
Posted 17 June 2012 - 01:02 PM
The only thing I can think to suggest is to use the debug window the check the contents of the data structure.
-
If I was in the same position as you, I would write a small bit of code that checks the data structure and displays its contents on screen one cell at a time (using the up/down keys to scroll through the ds_*).
The reason I would write it as opposed to just using the debug window supplied is so that I could see if I was using the read functions properly as well.
Also, looking at the ds_* size and comparing it to what you know it should be sometimes helps you find bugs.
Good luck!
-
If I was in the same position as you, I would write a small bit of code that checks the data structure and displays its contents on screen one cell at a time (using the up/down keys to scroll through the ds_*).
The reason I would write it as opposed to just using the debug window supplied is so that I could see if I was using the read functions properly as well.
Also, looking at the ds_* size and comparing it to what you know it should be sometimes helps you find bugs.
Good luck!
#13
Posted 17 June 2012 - 01:09 PM
Hm... I cannot seem to make this work... I suppose I can achieve a similar effect via an ATB that pauses whenever any character attacks and whenever any menu appears.
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users











