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.

Help with call scripts [Resolved]

The below scripts/conditional branches  are examples of what I have tryed (the text was just for testing) What I'm really trying to do is make it so that when (the hero/actor) has no weapon equiped, it will make a weapon called fists equip in its place untill a weapon is put in its place. I am looking for this because my battle system I'm using needs you to have a weapon equipped or it won't work. I've been having trouble with getting that result and I really want to avoid making a conditional branch for each weapon to do a check and see if it works.  So thanks in advance for any help.

This is there error I keep getting, it happens right after I press start (or after I click where the event is):
The error: [SyntaxError occurred while running script.]

Ok, I've tryed several things:

Code:
if @actor[1].weapon_id == 0 then 
          @actor[1].weapon_id == 1

Note: Each conditional branch is used seperatly and they are all not active at the same time. Also, the text was just a test to see if they would give the "Worked!" result. These are also working on Parallel Process

Conditional Branch: Script: If @actor[1].weapon_id == 0
         @>Text: Worked!
         @>
        Else
         @>Text: Didn't Work...
         @>
        Branch End

Conditional Branch: Script: If @actor.weapon_id == 0
         @>Text: Worked!
         @>
        Else
         @>Text: Didn't Work...
         @>
        Branch End

Conditional Branch: Script: If @actor[1].weapon_id == nil
         @>Text: Worked!
         @>
        Else
         @>Text: Didn't Work...
         @>
        Branch End

Conditional Branch: Script: If @actor.weapon_id == nil
         @>Text: Worked!
         @>
        Else
         @>Text: Didn't Work...
         @>
        Branch End


I have the above running on Parallel Process (tested seperatly and turned off all but the one I'm testing)
Then when ever I press start I will get this error: [SyntaxError occurred while running script.]
 
Your syntax is set up wrong. In a Conditional Branch, you don't need an "if", it's only necessary for Call Scripts. Conditional Branches pretty much are the "if"s. Instead, have something like
Code:
@>Conditional Branch: Script: @actor[1].weapon_id == 0

Although I'm not complete sure if that syntax is right either. It might be "@data_actor[1].weapon_id", but I'm not entirely sure. Just try them out, and tell if it works or not.
 
Its still not working, now I get a different error: [NoMethodError occurred while running script.
                                                                undefined method for `[]' nil:NilClass]

Here is what I tryed now (all tested seperatly on Parallel Process again):

Code:
@>Conditional Branch: Script: @data_actor[1].weapon_id == 0

Code:
@>Conditional Branch: Script: @data_actor[1].weapon_id

Code:
@>Conditional Branch: Script: @actor[1].weapon_id == 0
 
It doesn't work that way. Events don't have instance variables (@). You have to use globals. In this case, the script would be:
Code:
$game_party.actors[0].weapon_id == 0
Hope this works.

Explanation of why you got a nil:NilClass error. This is because the variable @actor and @data_actor does not exist in the current definition. As I said earlier, when running call scripts in events, there are no pre-defined variables apart from globals.
 

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