Problem writing a script

UnklePhil

Warper
Member
Joined
Aug 4, 2015
Messages
3
Reaction score
0
First Language
English
Primarily Uses
Im trying to create my first script, its meant to create an approval bar in the top right corner of the screen which fills up by using abilities calling the appropriate functions but i keep coming across the same error message. Can any scripters provide any advice on whats happening?

Approval Bar Script.txt

Error Message.png
 

Attachments

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
31,425
Reaction score
7,710
First Language
German
Primarily Uses
RMMV
I've moved this thread to Learning Ruby and RGSSx. Please be sure to post your threads in the correct forum next time. Thank you.


"Scripts" is for presenting finished scripts...
 

UnklePhil

Warper
Member
Joined
Aug 4, 2015
Messages
3
Reaction score
0
First Language
English
Primarily Uses
Sorry about that, thanks for moving it
 

Kai Monkey

Veteran
Veteran
Joined
Apr 3, 2012
Messages
166
Reaction score
119
First Language
RGSS3
Primarily Uses
Hi ♫

def crowdDispleaser #If the approval meter is more than 0 if ((Approval > 0) && (Approval <= 100)) #Decrease the approval meter by 5 points (CHANGE AMOUNT IF REQUIRED) Approval - 5 enddef damageTaken    #If the player takes damage    if ((mhp > 0) && ( mhp <= 100))    #Decrease the approval meter by 5 points (CHANGE AMOUNT IF REQUIRED)    Approval - 5    end 
If you look at crowdDispleaser and damageTaken you can see that you close the if structure, but never close the function. This breaks the whole script. What you mean to do is either

def crowdDispleaser #If the approval meter is more than 0 if ((Approval > 0) && (Approval <= 100)) #Decrease the approval meter by 5 points (CHANGE AMOUNT IF REQUIRED) Approval -= 5 endend def damageTaken    #If the player takes damage    if ((mhp > 0) && ( mhp <= 100))    #Decrease the approval meter by 5 points (CHANGE AMOUNT IF REQUIRED)    Approval -= 5    endendOR
Code:
def crowdDispleaser   #If the approval meter is more than 0   if ((Approval > 0) && (Approval <= 100))Approval -= 5enddef damageTaken    #If the player takes damage    if ((mhp > 0) && ( mhp <= 100))Approval -= 5end
Also, typing"Approval - 5" does not decrease the value of Approval by 5, for that you use "Approval -= 5" or "Approval = Approval - 5"

Lastly, I am fairly sure you cannot access Approval within the APB module at all, for two reasons:

  • You are not working within that module
  • It is a constant (unchangable) variable (as noted by the capital letter at the start)
There seem to be a lot of mistakes here, which is absolutely fine as you are very new to scripting. If you have other queries feel free to send me a PM.
/Kai
 
Last edited by a moderator:

UnklePhil

Warper
Member
Joined
Aug 4, 2015
Messages
3
Reaction score
0
First Language
English
Primarily Uses
Thank you so much, i'll try this out now but after seeing your reply I've noticed just how dumb the mistakes i've made were!
 

Kai Monkey

Veteran
Veteran
Joined
Apr 3, 2012
Messages
166
Reaction score
119
First Language
RGSS3
Primarily Uses
Oh, and also make sure you always indent you're code.

A lot of people new to programming think this is just some stylistic thing that doesn't really matter, but 70% of the time a new programmer asks for my help all I do is go and indent their code properly and they look over my shoulder and suddenly realise where their bug is.

Example:

Code:
def foo(x)if bar(x)x+=10elsewhile x < 10x.times do |e|msgbox 2*eendx+=2endendxend######### VS ################def foo(x)  if bar(x)    x+=10  else    while x < 10      x.times do |e|         msgbox 2*e      end      x+=2    end  end  xend
 
Last edited by a moderator:

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

Just beat the last of us 2 last night and starting jedi: fallen order right now, both use unreal engine & when I say i knew 80% of jedi's buttons right away because they were the same buttons as TLOU2 its ridiculous, even the same narrow hallway crawl and barely-made-it jump they do. Unreal Engine is just big budget RPG Maker the way they make games nearly identical at its core lol.
Can someone recommend some fun story-heavy RPGs to me? Coming up with good gameplay is a nightmare! I was thinking of making some gameplay platforming-based, but that doesn't work well in RPG form*. I also was thinking of removing battles, but that would be too much like OneShot. I don't even know how to make good puzzles!
one bad plugin combo later and one of my followers is moonwalking off the screen on his own... I didn't even more yet on the new map lol.
time for a new avatar :)

Forum statistics

Threads
106,018
Messages
1,018,357
Members
137,803
Latest member
andrewcole
Top