Jump to content


Photo

Unknown Variable?


  • Please log in to reply
7 replies to this topic

#1 Sharkitoon

Sharkitoon

    GMC Member

  • New Member
  • 59 posts

Posted 07 October 2010 - 12:41 PM

In my Create Event, In the Code Action - Power = 1
In My Step Event, In the Code Action - //If the mouse is held, increase the power variable
if mouse_check_button(mb_left) == 1
{
if power < 15
power += room_speed/5;
}
if mouse_check_button_released(mb_left) == 1
{
//Put all your arrow shooting code here
bullet = instance_create(x,y,FireArrow)
with bullet
{
speed = power
direction = image_angle
}
//Reset power to 1
power = 1
}


When i start the game and tried shooting,
an error says, Unknown Variable power
  • 0

#2 Uniquebum

Uniquebum

    GMC Member

  • New Member
  • 317 posts

Posted 07 October 2010 - 12:42 PM

capitals make a difference "Power" is not "power"
  • 0

#3 Sharkitoon

Sharkitoon

    GMC Member

  • New Member
  • 59 posts

Posted 07 October 2010 - 12:47 PM

I did that already, but still won't work... =(
  • 0

#4 Uniquebum

Uniquebum

    GMC Member

  • New Member
  • 317 posts

Posted 07 October 2010 - 12:51 PM

Only reason GM states that the variable is unknown is because you haven't stated it. Did you change the "Power" from the create event to "power"? If it still complains about power being unknown, you should show us your gmk file.
  • 0

#5 Sharkitoon

Sharkitoon

    GMC Member

  • New Member
  • 59 posts

Posted 07 October 2010 - 12:59 PM

http://gmc.yoyogames.com/index.php

I followed this tut
  • 0

#6 ND4SPD

ND4SPD

    GMC Member

  • GMC Member
  • 2180 posts

Posted 07 October 2010 - 01:37 PM

Hey that's my code :P haha

Your problem is here:
with bullet
{
speed = power
direction = image_angle
}


bullet doesn't have a variable called power, but the player does. In a with structure, you can refer to the instance that called the with with other.
So that needs to be:
speed = other.power;

BTW, you need to post the EXACT error message. The line and position is important.
  • 0

#7 Alfred0110

Alfred0110

    Programmer

  • New Member
  • 366 posts

Posted 07 October 2010 - 01:58 PM

You can't use power as a variable, because it's a function. Use another name, like pwr.

Edited by Alfred0110, 07 October 2010 - 01:59 PM.

  • 0

#8 Sharkitoon

Sharkitoon

    GMC Member

  • New Member
  • 59 posts

Posted 07 October 2010 - 01:58 PM

@ND4SPD

Your code works, but the direction don't, the image_angle doesn't work. =(

*SOLVED*

I did this,

direction = unit_archer.image_angle

=)

Edited by Sharkitoon, 07 October 2010 - 02:00 PM.

  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users