Jump to content


Photo

Controlling graphics through a controller object.


  • Please log in to reply
7 replies to this topic

#1 Cyber-seeker

Cyber-seeker

    GMC Member

  • GMC Member
  • 28 posts

Posted 02 January 2012 - 12:58 AM

Hi guys,

This one is a real mystery to me. I'm working on a turn-based RPG, and it works somewhat like this:
1. The BATTLE controller object activates a character,
2. The character makes the choices required (what kind of maneuver, the various choices within the maneuver).
3. Selects the target.

Okay, so I got that working just fine... now here's the problem.

4. The character who is activated moves to a predefined location on the screen based on the type of attack (e.g., in front of the enemy he punches) and then performs his attack (grunt), and then moves back to his starting position.

NOTE: All this is directed from the DRAWING controller object.

5. The battle engine is reset (or the BATTLE controller object).

Thing is, my code isn't working. It freezes up instantly, with no error messages, NOTHING!!! Here's the code:

defender = obj_attack.target;
attacker = global.playerparty[global.current_player];
type = obj_attack.type;
targets = obj_attack.targets;
//after gaining all useful data, destroy the object
with(obj_attack)instance_destroy();

dist_away = 30
back_x = attacker.x;
back_y = attacker.y;



if(type == 0)
{
do
{
with(attacker)
{
move_towards_point(obj_draw_battle.defender.x-obj_draw_battle.dist_away, obj_draw_battle.defender.y, 6);
}
}
until(point_distance(attacker.x, attacker.y, defender.x, defender.y) <= 6)

attacker.x = defender.x-dist_away;
attacker.y = defender.y;

effect_create_above(ef_cloud, 20,20, 2, c_red);

while(point_distance(attacker.x, attacker.y, back_x, back_y) > 7)
{
with(attacker)
{
move_towards_point(obj_draw_battle.back_x, obj_draw_battle.back_y, 6);
}
}
attacker.x = back_x;
attacker.y = back_y;
}

obj_battle_ctrl.count_down_start = room_speed*0.5;
obj_battle_ctrl.battle_on = false;

effect_create_above(ef_firework,100,100,2,c_black);
instance_destroy();



P.S. This code is activated in the Create Event in the DRAWING controller object

I'm suspecting that the while statement is to blame, but who knows?...

Regards,
Cyber-seeker :thumbsup:
  • 0

#2 TheouAegis

TheouAegis

    GMC Member

  • GMC Member
  • 4705 posts
  • Version:GM8

Posted 03 January 2012 - 06:16 AM

Comment out the WHILE loop. (put /* and */ around it) If it still freezes, it's your DO/UNTIL loop.
  • 1

#3 Cyber-seeker

Cyber-seeker

    GMC Member

  • GMC Member
  • 28 posts

Posted 05 February 2012 - 04:36 AM

Thanks for your answer,TheouAegis. Unfortunately, that didn't fix the problem. I originally had while loops in both instances, but it never worked, so I thought that I would try the DO/UNTIL statement as an experiment. Obviously, it failed. I have reworked my code a little, I hope that it is more understandable now.
Just in case this is important: this code is in a SCRIPT, and is called in a Creation Event.

Sincerely,
Cyber-seeker




if(type == 0)
{
attacker.direction = point_direction(attacker.x, attacker.y, attack_x, attack_y);
attacker.speed = 6;
while(attacker.x < (defender.x - dist_away) || attacker.y != defender.y)
{
if(attacker.y >= defender.y-6 && attacker.y <= defender.y+6) attacker.y = defender.y;
if(attacker.x >= defender.x-dist_away-6) attacker.x = defender.x-dist_away;
screen_redraw();
sleep(50);
}
attacker.speed = 0;

/*
while(point_distance(attacker.x, attacker.y, back_x, back_y) > 7)
{
with(attacker)
{
move_towards_point(obj_draw_battle.back_x, obj_draw_battle.back_y, 6);
}
}
attacker.x = back_x;
attacker.y = back_y;
*/
}

obj_battle_ctrl.count_down_start = room_speed*0.5;
obj_battle_ctrl.battle_on = false;
  • 0

#4 TheouAegis

TheouAegis

    GMC Member

  • GMC Member
  • 4705 posts
  • Version:GM8

Posted 05 February 2012 - 06:01 AM

What if you replace the || with && in your first WHILE loop?
  • 1

#5 Cyber-seeker

Cyber-seeker

    GMC Member

  • GMC Member
  • 28 posts

Posted 14 February 2012 - 10:59 PM

Well, I haven't tried that, but I'm pretty certain that's not the issue. My main problem right now is, nothing is moving!! The system seems frozen (although it isn't). Or are things moving and I just can't see it for some reason?
  • 0

#6 Cyber-seeker

Cyber-seeker

    GMC Member

  • GMC Member
  • 28 posts

Posted 14 February 2012 - 11:06 PM

Okay, here's something interesting:

In a new object, I gave orders for a spark to appear every STEP and the MOUSE POINT, like so:

Draw Event:

effect_create_above(ef_spark, mouse_x, mouse_y, 1, c_lime);

When the Draw_Graphics script was activated (the script that is causing me so much trouble), all the sparks, which normally disappear, remained on screen. It seems that everything is frozen, and graphics can change, but they, "leave 'ere skins 'ahind."

Any guesses anyone?... anyone.... anyone....
  • 0

#7 vann

vann

    GMC Member

  • GMC Member
  • 353 posts
  • Version:GM:Studio

Posted 15 February 2012 - 06:11 AM

Um,

Your while loop will be causing it. I think if you reread what TheouAegis initally said he was probably right, it's both your while and until loops that would cause your freeze. IE. if it still failed when you commented the while loop it was the until loop, because from my understanding both would have cause your system to hang from that inital code.

The reason why, is that using either move_towards_point or setting direction and speed, won't actually move the objects until a step passes. Since steps wont process until the while/until loops are escaped you're stuck.

If you want to visually see the fighters move then you need to put the check to see if its reached its target in the step event. You can give its initaly direction and speed orders in the create event still.

Now, if you do just want them to seem to appear in the desired spots without watching them move, then you need to change there position within the while loop in a different way. Something like this would work

moveSpeed = 5
directionToTarget = point_direction(attacker.x, attacker.y, defender.x, defender.y)
while(point_distance(attacker.x, attacker.y, defender.x, defender.y) > 10){
    attacker.x += lengthdir_x(moveSpeed, directionToTarget)
    attacker.y += lengthdir_y(moveSpeed, directionToTarget)
}

That will inch the object towards target.x until it's there, then escape the while loop. Visually though you will only see them appear next to each other, as this is done inside the creation event remember.

As I said, if you want to see them walk/run/drive/fly towards each other, set the direction and speed in creation, then do your if/then point_distance checks in the step event.

Edited by vann, 15 February 2012 - 06:17 AM.

  • 1

#8 Cyber-seeker

Cyber-seeker

    GMC Member

  • GMC Member
  • 28 posts

Posted 18 February 2012 - 12:09 AM

Thanks fellows for your help. The program is fixed. Cheers to all the great folks here on GMC! :thumbsup:

Edited by Cyber-seeker, 18 February 2012 - 05:52 PM.

  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users