Chaos Project

RPG Maker => General Discussion => Troubleshooting / Help => Topic started by: azdesign on August 15, 2013, 05:42:42 am

Title: long script inside script box resulting in syntax error
Post by: azdesign on August 15, 2013, 05:42:42 am
[RPG Maker XP]
Hi, I'm stuck on frustrating syntax error that occur whenever I input long script into an event
example code :
$some_variable[:instance].long_function_name('param1','param2',1,2,3)

Put the code into script box and here is how it shows up
$some_variable
[:instance].long_function_name
('param1','param2',1,2,3)

separated into 3 lines aka screw things up
the result is syntax error. I tried to fix it by removing space, putting additional parameter after "," in the line after, etc. But then sometimes it works, sometimes not. 50:50
To be sure that I don't make any mistake with the code, I put the code into a simple short function inside the script and call it from an event and it works, so I'm 100% certain that the mistake was not from my code, but from the script box

So my question is how to properly write long syntax into the script box that run as it should be even after being separated into multiple lines by script box ?

ps : I'm sorry if this is a duplicate topic of a similar problem. I tried searching it first but what I got was about syntax error from specific script someone else's made.  :O.o:
Title: Re: long script inside script box resulting in syntax error
Post by: winkio on August 15, 2013, 07:56:07 am
Go into your script editor, and write the following as a new script above main:

module QSC
  def self.sc1
    $some_variable[:instance].long_function_name('param1','param2',1,2,3)
  end
end


Then in the event script call, you can just put

QSC.sc1


If you have more, you can define self.sc2, self.sc3, etc. under the same QSC module.
Title: Re: long script inside script box resulting in syntax error
Post by: azdesign on August 16, 2013, 08:32:20 pm
I did that before actually. ", I put the code into a simple short function inside the script and call it from an event and it works,".
Hmm.. so I guess the script box is just like that and can't be helped. I thought it was just a simple word wrap, but apparently it wasn't.
Writing the syntax inside the script editor as a function and call it in the event seems the only way.  :uhm:

Thanks  :haha:
Title: Re: long script inside script box resulting in syntax error
Post by: KK20 on August 17, 2013, 02:31:41 am
If you truly want it to wrap, you can do this stupid little thing:

class Interpreter
 #--------------------------------------------------------------------------
 # * Script
 #--------------------------------------------------------------------------
 def command_355
   # Set first line to script
   script = @list[@index].parameters[0]
   # Loop
   loop do
     # If next event command is second line of script or after
     if @list[@index+1].code == 655
       # Add second line or after to script
       script += @list[@index+1].parameters[0]
     # If event command is not second line or after
     else
       # Abort loop
       break
     end
     # Advance index
     @index += 1
   end
   script.gsub!(/;/) {"\n"}
   # Evaluation
   result = eval(script)
   # If return value is false
   if result == false
     # End
     return false
   end
   # Continue
   return true
 end
end

All you have to do is make sure you put a semicolon to separate the different script calls. This script call will now work:

$game_party.actors.push($game_actors
[8]);
$game_party.actors[0].name = "Mr.
Orange Hair Guy";$game_party.
gain_gold(
1
0
0
0
)

And of course, notice how I put no semicolon at the end since that's the last essential call. Just only needs to be put in between.
Title: Re: long script inside script box resulting in syntax error
Post by: azdesign on August 18, 2013, 04:40:34 am
Thanks a lot, this is what I need, gonna try this right away  :D