Lol, you didn't need to post the entire script, but right away i see what you are TRYING to do exactly so it helps. (Don't worry, I won't take your idea/mess with your script/etc.)
Anyways, I'll see if I can help you and give you some pointers.
Firstly, I see you use alot of global variables (ex. $variable_name)
I would HIGHLY suggest you avoid using global variables as MUCH as possible. Global variables are accessible from anywhere in the game, and use up sometimes unnecessary memory. as a rule of thumb, if you do not need to access a variable outside an object, make an instance variable (ex. @variable_name)
Here is some reading on ruby variables to help you out:
http://www.techotopia.com/index.php/Ruby_Variable_Scope
Next, I would like to touch on some logical errors in your code. In all your if statements that check if something is equal to something, you use the assignment operator (=) when you should be using the equality comparison operator (==)
ex.
if energie_rem = 0
can_cut = false
end
should be
if energie_rem == 0
can_cut = false
end
Currently, your if statement assigns 0 to energie_rem (which will always return "true" thus, the next line of code WILL ALWAYS execute, making can_cut false)
Also, if checking if a variable is equal to true or false, you do not need to use the equality operator
ex.
if variable == true
# Code
end
can be
if variable
# Code
end
to check for false you can use the not (!) logical operator
ex.
if !variable
#code
end
Also, you should use double sided if statements over stacked if statements when possible, this will use much less computing power (for the most part)
Also, any method that should return a value should return a value. If there is no return statement, then 'nil' is returned (I might be wrong, but I am pretty sure).
ex. ( I will use your can_cut method as an example, I have changed it to return a value as well as changed it to multi-sided if statement as opposed to stacked if statements and simplified some of the logic)
def can_cut
if $data_actors[weapon_id] == NUKA::WOODCUTTING_WPN_ID && $job_learn
can_cut = true
else
return false # If the $job_learn is false or they do not have the right weapon, then they cannot cut
end
#----If you are out of energie, you can't cut----------------------------------#
if energie_rem == 0
return false
elsif energie_rem < 0
energie_rem = 0
return false
elsif energie_rem > 100
energie_rem = 100
end
return can_cut # Return whether the player can cut or not
end #end of define "can_cut"
You could actually simplify this even moreso:
def can_cut
# returns the result of the weapon equal to the correct id AND job_learn AND energie_rem greater than 0
# if ALL of these are TRUE, the result is TRUE, and therefore the player can_cut.
return ($data_actors[weapon_id] == NUKA::WOODCUTTING_WPN_ID && $job_learn && energie_rem > 0)
end #end of define "can_cut"
Also, I would like to mention that
$data_actors[weapon_id] doesn't make any sense. This is using weapon_id (a local variable which has not been initialized, and thus "nil") within the $data_actors global hash variable, which contains all the actor data from the database. $data_actors[nil] is always going to be a nil value.
what you are probably looking for is the party leader's current weapon, to get this use: $game_party.actors[0].weapon_id
Also, be careful when trying to assign a literal to a variable:
@logs_type = A
this will look for the constant variable named A, which does not exist, so therefore @logs_type will be nil in this statement. If you want to set it to the letter A use:
@logs_type = "A"
The last thing I want to touch on, is your use of the "case" statement.
case statments, can be merged:
ex:
case $woodcutting_level
when 1
#do this
when 2
# do this
when 3
# do this
end
also, what you have at the end there will not work
when 1 [1...9]
i am assuming you are checking for the level from 1-9?
use:
case $woodcutting_level
when 1..9 # 1 - 9 inclusive
# Do this
when 10..19 # 10-19 inclusive
# Do this
end
etc.
Also, be careful when using ranges (number...number or number..number)
... is range EXCLUSIVE ex. (1...5 is 1, 2, 3, 4)
.. is range INCLUSIVE ex. (1..5 is 1, 2, 3, 4, 5)
Ruby Ranges:
http://www.techotopia.com/index.php/Ruby_Ranges
also, you may find these useful:
Ruby if statements : http://www.howtogeek.com/howto/programming/ruby/ruby-if-else-if-command-syntax/
ruby case statements : http://www.skorks.com/2009/08/how-a-ruby-case-statement-works-and-what-you-can-do-with-it/
Sorry for the novel, but I hope this helps. Learning to script can be a VERY daunting task, especially if you are learning it on your own and have no experience in programming. Good luck, if you need any further clarification/help, let me know.
EDIT: I forgot to mention, that last bit you have:
$Woodcutting.new
is an invalid statement.
$ is the global variable indicator, and .new is ONLY used when initializing a class/object.
$variable = Woodcutting.new makes sense, but what you have now will produce errors.