Problem writing a script

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
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...
Sorry about that, thanks for moving it
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
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!
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:

Spoiler
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

Original thread: https://forums.rpgmakerweb.com/threads/problem-writing-a-script.43234/