Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Noobie Cheeze needs Help!

Okay i need help with my scripting..I am just starting. I know some stuff about scripting. But! I am trying to make a gravity script for my game (It's a platform) But if anyone wants to help, Go ahead!

*Note* Yes..This is my first (Kinda) script

1: How do you use a variable (Thats made with events[For Terrain]) in a script? could someone just give me the basics? Thanks!

P.S. I am going to put everything that has to do with my scripts and me needing help in here
 
Sweet thanks!..And what is the directions in scripting..Like i need it if it is faceing left or right

EDIT: I need it where if the variable doesnt equal the number it does something
EDIT2:
Code:
#------------------------------------------------------------------------------
# Gravity script
#  By Cheeze
# V 0.0.1 
#------------------------------------------------------------------------------
$game_variables[25]
begin
  if $game_variables[25]not 2
    if $game_player.direction=6
      $game_player.move_lower_right
      until 
        $game_variables[25]=1,2
      end
    else
      if $game_player.direction=4
        $game_player.move_lower_left
        until
          $game_variables[25]=1,2
        end
      end
    end
  end
end

...Thats as far as i have gotten and it stops at line 7..I need a personal tutor x_X

EDIT 3: Alright, I found a tut and then i just started tweakin with the script and I get to line 7 and it quits on me
Code:
#------------------------------------------------------------------------------
# Gravity script
#  By Cheeze
# V 0.0.1 
#------------------------------------------------------------------------------
begin
  if $game_variables[0025]!= 2
    if $game_player.direction=6
      $game_player.move_lower_right
    end
  else
    if $game_player.direction=4
      $game_player.move_lower_left
    end
  end
end

It says "Script 'Gravity' line 7: NoMethodError occured. undefined method '[]' for nil::NilClass"

I want it so that the actor moves diagnol until it touches terrain 2 or 1
 
try this:
if $game_player.direction == 6

This confuses a lot of beginner programmers. But there is a difference between "=" and "==". The single equal sign (=) is called the assignment operator, it tries to make whatever is on the left equal to that on the right. The double equal sign (==) is called a logical operator, it compares whatever is on the left and on the right and if they both hold the same value then "true" is returned.

If it makes it easier to understand, all you need to know right now is that whenever you want to make something equal something else, you use "=", and whenever you try and compare values in an if statement, you use "==".

Also the reason why you are getting an error on line 7 is because you are trying to access $game_variables which isn't declared at the point in your script, this is most likely because you have your script added to the beginning of the game code at the very top of the script editor (Before Game_Temp, Game_Variables, act.). Whenever you add a custom code into your game, always add at the bottom of all the other scripts before "Main" in the script editor. This way all of the other game code as been created already and it doesn't confuse the editor when you try and look for things that doesn't exist yet.

Those are the most immediate things I see, but its kind of late so I'm going to bed now.
 
Cheeze;204151":354m57dj said:
Code:
#------------------------------------------------------------------------------
# Gravity script
#  By Cheeze
# V 0.0.1 
#------------------------------------------------------------------------------
begin
  if $game_variables[0025]!= 2
    if $game_player.direction=6
      $game_player.move_lower_right
    end
  else
    if $game_player.direction=4
      $game_player.move_lower_left
    end
  end
end
It says "Script 'Gravity' line 7: NoMethodError occured. undefined method '[]' for nil::NilClass"

Correct me if I'm wrong, but does it show this error message when you start the game? If so, then I know why. It is running that script as soon as you start the game, and game_variables have not loaded yet. You may want to place your conditional statements within the game_player class within the update method. also, you do not need the two zeros before the 25.
 
@ Draycos: yeah it wont even go to the game title

@ Kadoba: It is at the very bottom before main and it still does the same thing about nil::NilClass

EDIT: Okay I need it where it doesnt equal 2...I tried "!==" and it took off the nil:NilClass part but it still goes to a syntax error
 
"!=" is not equal to

Question, How exactly do you want this to work? anytime that variable equals 2 the player moves, or only if a button is pressed, or what? let me know and I can show you better how to fix this.
 
ok. try something like this:

Code:
#------------------------------------------------------------------------------
# Gravity script
#  By Cheeze
# Version ... 
#------------------------------------------------------------------------------

#------------------------------------------------------------------------------
# Game Player
#------------------------------------------------------------------------------
class Game_Player
  #alias the update method
  alias cheeze_gravity_update update
  def update
    # test if variable 25 is not 2
    if $game_variables[25]!= 2
      #is the player facing right?
      if $game_player.direction=6
        $game_player.move_lower_right
      #is the player facing left?
      elsif $game_player.direction=4
        $game_player.move_lower_left
      end
    #if variable 25 is 2
    else
      #do normal movement
      cheeze_gravity_update
    end
  end
end

That might work. you do store the terrain tag in game variable 25, right?
 
sorry, replace "$game_player.direction=6" with "@direction == 6" and "$game_player.direction=4" with "@direction == 4" also change "$game_player.move_lower_left" with just "move_lower_left" and "$game_player.move_lower_right" with "move_lower_right"
 
Then i'll have to wait until I can get to my computer at home, either tomorrow(monday), or tuesday. I'm at work right now and don't have access to rmxp to test it. If no one has helped you by then, I'll figure something out for you.

I like the quiz of random-ness. Especially how it ends. I work at subway, so I definately said no. LoL
 
Ok, here you go. I tested this, and it does seem to work. I also used terrain_tag instead of game variable 25 so that you do not have to use an in-game variable.
here's the script:
Code:
#------------------------------------------------------------------------------
# Gravity script
#  By Draycos Goldaryn for Cheeze
# Version 2 
#------------------------------------------------------------------------------

#------------------------------------------------------------------------------
# Game Player
#------------------------------------------------------------------------------
class Game_Player
  #alias the update method
  alias cheeze_gravity_update update
  def update
    # test if the player is not on a terrain tag of 2
    if terrain_tag != 2
      #is the player facing right?
      if @direction == 6
        move_lower_right
      #is the player facing left?
      elsif @direction == 4
        move_lower_left
      end
    end
      #do normal movement
      cheeze_gravity_update
  end
end

Tell me if this works for you, and if not, what needs changing?
 
what if you worked out some funky loop and a quadratic equation?
The y = x^2 produces a parabola. If you get RMXP to add the y variable to $game_player.y while looping through this update of jumping and changing x each time, the player should move through the parabola.

if that doesn't make sense now...it may or may not after grade 10 math...don't feel bad if it doesn't XD
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top