The RPG Maker Resource Kit

RMRK RPG Maker Creation => RPG Maker General => General Scripting => Topic started by: Demonic Blade on January 08, 2008, 06:34:03 PM

Title: Problems with a script I made... (I'm a newb scripter...)
Post by: Demonic Blade on January 08, 2008, 06:34:03 PM
Okay. First of all, this was just for fun, nothing fancy, also the first thing I've ever done with scripting. I just wanted something very simple, it's only about 10- 20 lines. Please, don't get harsh, this was just a first-try with the Scite editor thing.

Okay, now I just wanted to make an event in rmxp, asking you for gender and then age. If you chose to be a "Boy" then I used a call script to type:
(Note that I also tried doing it with "var_girl")
gen_girl = false
If u chose to be a girl, it'd become true.

Then afterwards, you're asked if you're old or young. Simple too:
You choose to be "Old" I call script and it says:

age_old = true
If you chose to be young, then it'd be
age_young = true

But enough talk, I get an error. The whole script:


if age_old == true
then age_young = false
elsif age_old == false
then age_young= true
end
end
# Theres about 10 lines of comments here XD...
if age_old == true
  then p "I am an old idiot"
elsif age_young == true
  if gen_girl == false
   then p "I am a young boy"
  elsif gen_girl == true
      then p "I am a young girl"
   end
end
end


The error is on line 6. I called the script "Age_Gender"
Tell me if you need more info about it, 'cuz I'll try to get it then.
Title: Re: Problems with a script I made... (I'm a newb scripter...)
Post by: Leon_Westbrooke on January 08, 2008, 06:45:24 PM
Looks like you have 1 too many 'end's in there.

if age_old == true
  then age_young = false
elsif age_old == false
  then age_young= true
end
end


See?
Title: Re: Problems with a script I made... (I'm a newb scripter...)
Post by: Demonic Blade on January 08, 2008, 07:02:45 PM
NOTE: These errors come when I start the game, not after talking to the event!
Now: What do u mean? That's not how I wrote it. I wrote:

  end
end


not

end
end

But does it make a difference?

EDIT:
I tried removing one of the ends. Now I have an error at line 26. That's another end. I remove that and I get an error in line 1: if age_old == true
It might be because I deleted the wrong end, I'm gonna try that right now...

EDIT: Same problem...  :( Now it looks like this:

if age_old == true
then age_young = false
elsif age_old == false
then age_young= true
end
#-----------------------------------------------------------------------------------------------------
#Excactly ten lines of comments here.
#-----------------------------------------------------------------------------------------------------
if age_old == true
  then p "I am an old idiot"
elsif age_young == true
  if gen_girl == false
   then p "I am a young boy"
  elsif gen_girl == true
      then p "I am a young girl"
end
end


Also, would it be easier to have one variable to define age? So I have age_old instead of also "age_young? Ah heck, I'll try it. Might work miracles...
Title: Re: Problems with a script I made... (I'm a newb scripter...)
Post by: Kokowam on January 08, 2008, 08:19:55 PM
Last I checked, you don't use "then" in a conditional. If you have too many "end"s, the game checks all scripts to see if they're correct in syntax. Then when you run it, it runs and sees if it works. Fix it. Use good scripting spacing. White space is your friend.
Title: Re: Problems with a script I made... (I'm a newb scripter...)
Post by: modern algebra on January 08, 2008, 08:37:13 PM
Well, if it is an error at line 26, why only post the first ten lines?  :police:

Also, you are correct that it is redundant to have two boolean variables for age as there are only two positions. Also, the 'then' are redundant, but they also do not hurt as far as I know. The then is really only necessary if you put it on the same line as the if statement.

Also, as moo says, you do not need to run the script for the player to recognize syntax errors.

In any case, please post the entire script.
Title: Re: Problems with a script I made... (I'm a newb scripter...)
Post by: Kokowam on January 08, 2008, 10:01:43 PM
Also, an "end" works for the most recent thing that can be ended. Like...

Class Poop

def pooper
*stuff*

end.

Although this lines up with Class Poop, it works with def pooper. There really isn't such a thing as "removing the wrong end." Also, post up the whole script, like MA says, and we could probably re-do the error and fix it for you.

P.S.: If he does post up the whole script, can I have a whack at solving it before you guys do? Or at least try before you post it up so I don't cheat. XD Like a one day grace period after I notice it, lol.
Title: Re: Problems with a script I made... (I'm a newb scripter...)
Post by: Demonic Blade on January 09, 2008, 07:16:37 PM
I did post the whole thing... Oh, and I haven't tried calling the full script, I only put it in the script editor. As I said, there are 12 lines of comments. The "There's about 10 comments here" is actually 12 lines... ::).
Title: Re: Problems with a script I made... (I'm a newb scripter...)
Post by: Kokowam on January 09, 2008, 08:30:30 PM
Soo....

if age_old == true
age_young = false
elsif age_old == false
  age_young= true
end
end
# Theres about 10 lines of comments here XD...
if age_old == true
  then p "I am an old idiot"
elsif age_young == true
  if gen_girl == false
   then p "I am a young boy"
  elsif gen_girl == true
      then p "I am a young girl"
   end
end
end


[spoiler=Before 10 lines of comment]
Your first conditional branch before the comments could probably be turned into:

if @age_old == true
@age_young = false
else
@age_young= true
end

Since there's nothing other than age_young and age_old. Also, try adding an @ like I did so that accessibility is not an issue (just in case :P).
[/spoiler]

[spoiler=After 10 lines of comment]

if @age_old == true
p "I am an old idiot"
elsif @age_young == true
  if @gen_girl == false
   p "I am a young boy"
   elsif @gen_girl == true
    p "I am a young girl"
   end
  end
end
end

You missed an "end" and I changed it to have @variables.
[/spoiler]
Maybe try this? :P
Title: Re: Problems with a script I made... (I'm a newb scripter...)
Post by: tSwitch on January 09, 2008, 09:18:50 PM
umm
wouldn't this would be -much- easier to handle with event processing?

that aside
this can be done with scripts, but I think you're interpreting the way the script system works incorrectly
the scripts aren't compiled and run constantly, there is no call for all those conditionals you made
meaning that regardless of if you have proper syntax, it'll never be executed
you'd need to make a class, and at least a method to call all those ifs
not only that but the booleans should be class specific (seeing as you don't want to use event accessed variables) and you'd need to change them with the following syntax


$class_name.boolean_name = false


have you seen blizzard's scripting tutorial?
Title: Re: Problems with a script I made... (I'm a newb scripter...)
Post by: Demonic Blade on January 10, 2008, 06:30:39 PM
No, I only read constance's (RPG's)... And as I said, this was mainly just for fun, but I wanted to try it out. AND I don't understand the class thing, I'm not even sure he mentioned that in the script. But I'll try out blizz's scripting tut then... later...
Title: Re: Problems with a script I made... (I'm a newb scripter...)
Post by: Kokowam on January 10, 2008, 08:15:40 PM
Holy crap, Blizz finished his scripting tutorial?
Title: Re: Problems with a script I made... (I'm a newb scripter...)
Post by: tSwitch on January 10, 2008, 09:25:26 PM
idk if it's done but there's a good amount of it from what I saw

Quote from: Demonic Blade on January 10, 2008, 06:30:39 PM
No, I only read constance's (RPG's)... And as I said, this was mainly just for fun, but I wanted to try it out. AND I don't understand the class thing, I'm not even sure he mentioned that in the script. But I'll try out blizz's scripting tut then... later...

you need to understand classes and defs or you will never be able to script
simple fact k?
Title: Re: Problems with a script I made... (I'm a newb scripter...)
Post by: Demonic Blade on January 12, 2008, 11:36:28 AM
Okay, okay. No need to get mean (which u aren't, but I had to say something right?). But let's face it. It took me a couple of days to read it, and by that time I had forgotten most of the first things. "You should read it again then" you'll say, but I don't want to right now, 'cuz I don't have that much time! Besides, we've got a bunch of homework since we're doing a musical in school at the moment, and so we have no normal classes. Oh, and Mastermoo, I have no idea. I've never heard of it anyhow...