[EDIT] Below is the original post, I just though I should add the most recent script version up here so that people do not read through the old version and offer feedback based on it, rather then the more current version. I will keep updating this version every time I post now. Thanks
Hello everyone,
Basically I would like someone to look over my script that I am writing and give me feedback on how things should and shouldn't be done, if I have done things in the right manner that kind of thing. This is the first time I have ever attempted to write an actual script, ever! And I don't know a scripting language either, just some basics I have picked up while reading over others scripts or editing scripts with little tweaks. And I have done a little course with basic Java which helped a lot. The whole thing was written yesterday, for start to the point it is now. Zarieb (I hope thats spelt right) helped me with the following which I added this morning. But that was just a few line so I don't count it as working on it, when I already knew where they where to go.
1) Changing the self switches
2) Changing the graphic of the event
3) Gave me this so that step two works correctly
When I run the game I receive syntax error for 1 or 2 (Above) only when its inside my script though, what am I doing wrong? Thanks to anyone who can help with that.
About the script, its designed to be a farming script.
1) player plants a seed in the plot (Not complete but that will be another script anyway, Window to check the seeds and call the plant function once a seed is seleced)
2) when the player plants the seed "plant" is called from the script below to set the plot up and record what was planted that kind of thing.
3) "check" is called every so often by a parallel event to check if the plants have matured to the next stage
3.5) because the event checking is parallel and not the event itself the player can interact with the plot so it can be watered. Adding to the water level (Not fully implemented into the script yet)
4) if they are ready changes the plant/plot to the next image and to the next page of the event.
5) once the plant/plot is ready to harvest the player clicks on it and "Harvest" is run to collect the plant (This is not finished yet because I don't know what the script is to add an item, but I have it setup pretty close and ready to simply insert it.
Here is the script
I am not very good with the commenting or anything script related for that matter. Any help or feedback is appreciated. However being mean or calling me stupid for how badly the script has turned out isn't nice :P.
Also I apologize if this post is in the wrong section.
If you need any more information after reading my commenting please ask, and I will do my best. Thanks everyone!
EDIT
If possible, could someone please test this script for syntax errors? Above when I said the codes that I were given results in syntax errors that doesn't seem to be true. After I added more comments those lines of code have moved down, but I still receive syntax errors on line "34" and "63" which are now comments and not even coding. Would anyone have any idea why this is happening? I have tried copying the script to a new project and have the same result. Could it just be my computer? Thanks again for any help offered
Code:
#-------------------------------------------------------------------------------
# * Farming Script
#-------------------------------------------------------------------------------
#The "Order" data is entered below is as follows, for plant 1 you add its information
#seperatly into the arrays, e.g. the first position of each array here is an example
#
# @plants_times = [plant one's growing time, plant two's growing time, plant three's growing time]
# @plants_exp = [plant one's exp, plant two's exp, plant three's exp
# Continue filling in the data like this, so all the data in the "first" slot of these varibles
# belongs to the "first" plant and so on.
# There is an explaination about what each varible is next to it so you know what information to enter
# This farming system runs off real time, checking the computers data and time
# and uses this to calculate when a plant has grown to the next stage.
# There are four stages for each plant, seedling, sprout, bud and bloom (Bloom is fully grown)
#-------------------------------------------------------------------------------
class Farming
attr_accessor :plants_times, :plants_exp, :plants_water
attr_accessor :plants_itemid, :plants_herbid, :plants_stages
attr_accessor :plants_list, :plants_graphics, :plants_column
attr_accessor :plot_ID, :event_ID, :seeds_page
def initialize
#Plant Arrays and Information (Found this easier then multidementional arrays or other methods.)
#In Minuets, the amount of time it takes the plant to gorw through each stage.
#To find the full length of time the plant takes to grow times your minuets by 3
@plants_times = [2, 3, 1, 5]
# The amount of exp gained from growing the plant
@plants_exp = [3, 3.5, 0.01, 6]
#Number of times plant needs to be watered each stage
@plants_water = [1, 2, 3, 3]
#The item id of the seed
@plants_itemid = [1, 2, 3, 4]
#The item id of the produced plant
@plants_herbid = [5, 6, 7, 8]
#Do not change this
@plants_stages = [2, 4, 6, 8]
#If you do not set the following names will be generated by the names of the item produced.
@plants_list = [] #Add in the "names" of the plants in order. Put them in "" and adding a commar after each one
#If nothing is set here the graphics for you plants will be set to their names e.g. "plants_name.png"
@plants_graphics = [] #If setting the graphics files yourself put them here in order
#If you did not set custom graphics do no set this
@plants_column = [] #If setting custom graphic files select the colum of the plant here, 0 = first column, 1 = second column, ect...
#For calling Famring Scene
@plot_ID
@event_ID
#Needed for Scene_Farming
@seeds_page = 0
end
#Basic Plant Array Structure (No longer needed at this time)
@basic_plant = ["Growth Time", "Exp", "Water Needed", "Seed ID", "Herb ID", "Graphics", "Column"]
#Basic Plot Array Structure (So that I know where the information I need is stored when using "$game_farming_plots")
@basic_plot = ["Plant Type", "Growth State", "Water Level", "Time Planted", "Event ID", "Map ID"]
#Set Number of plots to use (Change this to the number of plots used in the game)
@number_of_plots = 1
#Create Arrary for multidentionalisim (I am pretty sure thats a made up word *Chuckels*)
$game_farming_plots
#Allows Data to be Accessed
$game_farming = Farming.new
def self.setup
#Checks how long each array should be (I didn't set this in stone so I could add or take features e.g. watering)
l = @basic_plot.length
#Checks how many plots are needed
n = @number_of_plots
#Ceates the multidementional Array
$game_farming_plots = Tools.mda(n, l)
#If the user has not set a list of plant names, the names are compiled from the end items names.
if @plants_list == nil
i = 0
while i < @plants_itemid.length
id = @plants_itemid[i].to_i
@plants_list[i] = $data_items[id].name
i = i + 1
end
end
#If the user has not set a list of plant names, the names are compiled from the end items names.
if @plants_graphics == nil
z = 0
while z < @plants_list.length
@plants_graphics[z] = @gplants_list[z].to_s
z = z + 1
end
end
#Loops runs to convent the users input from seconds into minuets
t = 0
while t < @plants_times.length
@plants_times[t] = @plants_times[t].to_i * 60
t = t + 1
end
end
def self.plant(itemID)
#PlotID is the plot number assigned to the event, itemID is the item planted's number
#eventID is so that the plot and event as bound and change be changed together
#Gets the event's ID
eventID = @event_ID
#Gets the plot's ID
plotID = @plot_ID
#Sets the index i to 0
i = 0
#Gets the plants id number by comparing the item id using i as the index
while i < @plants_itemid.length
#checks if the itemID given matches the item id at i in $game_farming_itemid
if itemID == @gplants_itemid[i]
#if the item id matches sets the varible plantID to the plants id
plantID = i
#Sets i to the length of #game_farming_plants_itemid so to finish the when loop
i = @plants_itemid.length
end
#if the item id's did not match adds 1 to i and checks the next value fot a match
i = i + 1
end
#Sets time to the current time, including day and year.
time = Time.now
mapID = $game_map.map_id
#sets the selected plot to the selected plant (Stage to 0, water level to 0, and time plant needs, which event the plot is)
$game_farming_plots[plotID] = plantID, 0, 0, time, eventID, mapID
#Changes the event to the next page ready to turn into a plant
$game_self_switches[[mapID, eventID, "A"]] = true
#refresh map so that the changes are shown
$game_map.need_refresh = true
#Change the plots image to a seedling after checking if the player as set custom graphics
if @plants_graphics == nil
$game_map.events[eventID].character_name = @plants_list[plantID]
#First column from the left facing up (Defult settings)
$game_map.events[eventID].subgraphic!(0, 2)
else
#If the player as set up their own graphics use them instead
$game_map.events[eventID].character_name = @plants_graphics[plantID]
#Set the graphic to the plant selected by the user and set to seedling (2)
$game_map.events[eventID].subgraphic!(@plants_column[plantID], 2)
end
#refresh map so that the changes are shown
$game_map.need_refresh = true
end
def self.check(plotID)
#Sets up all the data that may be needed for the method so it does not need to be set by seperate sections
#Sets the plots event ID
eventID = $game_farming_plots[plotID][4]
#Checks which map the plot is on
mapID = $game_farming_plots[plotID][5]
#Set growth to the time the plant takes to grow each stage
plantID = $game_farming_plots[plotID][0]
#Set start to time of planting
start = $game_farming_plots[plotID][3]
growth = @plants_times[plantID]
#to find when the next stage is complete
finish = start + growth
#Set time to current time
time = Time.now
if time >= finish
#Set plant to the plant type
plantID = $game_farming_plots[plotID][0]
#Check what stage the plot it up to
stage = $game_farming_plot[plotID][1]
#Checks if the plants has been watered enough to advance
if $game_farming_plots[plotID][2] >= @plants_water[plantID]
#Adds one to the plots/plants stage
$game_farming_plots[plotID][1] += 1
#Resets the plants water level
$game_farming_plots[plotID][2] -= 1
#refresh map so that the changes are shown
case stage
when 1
#Sets the plots graphic to that of the next stage
$game_map.events[eventID].subgraphic! (@plants_column[plantID], 4)
#refresh the map so that the changes are shown
$game_map.need_refresh = true
when 2
#Sets the plots graphic to that of the next stage
$game_map.events[eventID].subgraphic! (@plants_column[plantID], 6)
#refresh map so that the changes are shown
$game_map.need_refresh = true
when 3
#Sets the plots graphic to that of the next stage
$game_map.events[eventID].subgraphic! (@plants_column[plantID], 8)
#change self switch d on for the plot
$game_self_switches[[mapID, eventID, "B"]] = true
#refresh map so that the changes are shown
$game_map.need_refresh = true
end
end
end
end
def self.harvest(plotID)
#Get plant ID
plantID = $game_farming_plot[plotID][0]
#Get Map ID
mapID = $game_farming_plot[plotID][5]
#Gets the exp for growing such plant
exp = @game_farming_plants_exp[plantID]
#add the exp to the skill farming (I created a skillbook to keep record of exp and levels and to display this information to the user)
#When the exp is added skillbook also checks if a level should be awarded and that kind of thing
Skillbook.addexp("farming", exp)
#Resets the plots switches ready for replanting
$game_self_switches[[mapID, eventID, "A"]] = false
$game_self_switches[[mapID, eventID, "B"]] = false
$game_self_switches[[mapID, eventID, "C"]] = false
$game_self_switches[[mapID, eventID, "D"]] = false
#refresh map so that the changes are shown
$game_map.need_refresh = true
#clears the plots data ready for reuse and so that it can not cause any issues (Just in case really)
$game_farming_plots[plotID].clear
#sets the item to gain
item = @game_farming_plants_items[plantID]
#adds the item nessacry
$game_party.gain_item(item, 1)
#Sets V6 to the name of the plant recived so that it can be displayed to the player in the textbox
$game_variables[6] = @game_plants_list[plantID]
end
end
Hello everyone,
Basically I would like someone to look over my script that I am writing and give me feedback on how things should and shouldn't be done, if I have done things in the right manner that kind of thing. This is the first time I have ever attempted to write an actual script, ever! And I don't know a scripting language either, just some basics I have picked up while reading over others scripts or editing scripts with little tweaks. And I have done a little course with basic Java which helped a lot. The whole thing was written yesterday, for start to the point it is now. Zarieb (I hope thats spelt right) helped me with the following which I added this morning. But that was just a few line so I don't count it as working on it, when I already knew where they where to go.
1) Changing the self switches
Code:
$game_self_switches[[$game_map.map_id, eventID, "A"]] = false
Code:
#Change the plots image to a seedling
$game_map.events[eventID].character_name = 'Grid Seeds'
#First column from the left facing up
$game_map.events[eventID].subgraphic!(0,8)
Code:
class Game_Character
attr_writer :character_name
def subgraphic!(pattern, direction)
# Pattern
@original_pattern = pattern
@pattern = pattern
# Direction
@original_direction = direction
@direction = direction
end
end
When I run the game I receive syntax error for 1 or 2 (Above) only when its inside my script though, what am I doing wrong? Thanks to anyone who can help with that.
About the script, its designed to be a farming script.
1) player plants a seed in the plot (Not complete but that will be another script anyway, Window to check the seeds and call the plant function once a seed is seleced)
2) when the player plants the seed "plant" is called from the script below to set the plot up and record what was planted that kind of thing.
3) "check" is called every so often by a parallel event to check if the plants have matured to the next stage
3.5) because the event checking is parallel and not the event itself the player can interact with the plot so it can be watered. Adding to the water level (Not fully implemented into the script yet)
4) if they are ready changes the plant/plot to the next image and to the next page of the event.
5) once the plant/plot is ready to harvest the player clicks on it and "Harvest" is run to collect the plant (This is not finished yet because I don't know what the script is to add an item, but I have it setup pretty close and ready to simply insert it.
Here is the script
Code:
class Farming
#Plant Arrays and Information (Found this easier then multidementional arrays or other methods.)
$game_farming_plants_list = ["Golden Wattle", "Orange Fungi", "Anthers", "Rosmary"]
$game_farming_plants_times = [2, 3, 5, 5]
$game_farming_plants_stageone = ["Golden Wattle", "Orange Fungi", "Grid Flowers", "Random"]
$game_farming_plants_stagetwo = ["Golden Wattle", "Orange Fungi", "Grid Flowers 2", "Random"]
$game_farming_plants_stagethree = ["Golden Wattle", "Orange Fungi", "Grid Flowers 3", "Random"]
$game_farming_plants_exp = [3, 3.5, 0.1, 6]
$game_farming_plants_water = [1, 2, 3, 3]
$game_farming_plants_itemid = [1, 2, 3, 4]
#Basic Plant Array Structure (No longer needed at this time)
$game_farming_plant_basic_plant = ["Growth Time", "Stage One", "Stage Two", "Stage Three", "Exp", "Water Needed"]
#Basic Plot Array Structure (So that I know where the information I need is stored when using "$game_farming_plots")
$game_farming_basic_plot = ["Plant Type", "Growth State", "Water Level", "Time Planted", "Time Ready", "Event ID]
#Set Number of plots to use (Change this to the number of plots used in the game)
$game_farming_number_of_plots = 1
#Create Arrary for multidentionalisim (I am pretty sure thats a made up word lol!)
$game_farming_plots
def self.setup
#Checks how long each array should be (I didn't set this in stone so I could add or take features e.g. watering)
l = $game_farming_basic_plot.length
#Checks how many plots are needed
n = $game_farming_number_of_plots
#Ceates the multidementional Array
$game_farming_plots = Tools.mda(n, l)
end
#(PlotID is the plot number assigned to the event, plantID is the planted chosen to grow (Number form to information can be pulled from the array),
#eventID is so that the plot and event as bound and change be changed together without having to request which event to change)
def self.plant(plotID, plantID, eventID)
#Sets the time the plot was planted V1 is hours, V2 is minuets
#Becuase V2 is in the format "00" / by 100 then adding to V1 gives us the format "00.00"
time = $game_variables[1].to_i + $game_variables[2].to_i / 100
#sets the selected plot to the selected plant (Stage to 1, water level to 0, and time plant needs, which event the plot is)
$game_farming_plots[plotID] = [$game_farming_plants_list[PlantID], 1, 0, time, $game_farming_plant_times[plantID], eventID]
#Change the plots image to a seedling
$game_map.events[eventID].character_name = 'Grid Seeds'
#First column from the left facing up
$game_map.events[eventID].subgraphic!(0,8)
end
def self.check(plotID)
#Sets the plots event ID
eventID = $game_farming_plots[plotID][5]
#Set start to time of planting
start = $game_farming_plots[plotID][3]
#Set growth to the time the plant takes to grow each stage
growth = $game_farming_plots[plotID][4]
#to find when the next stage is complete
finish = start + growth
#Set time to current time
time = $game_variables[1].to_i + $game_variables[2].to_i / 100
#Subtract time now from the plant is ready if the stage is complete
if (finish - time) == 0
#Set p to the plant type
plant = $game_farming_plots[plotID][0]
#Check what stage the plot it up to
stage = $game_farming_plot[plotID][1]
if stage == 1
picture = $game_farming_plants_stageone[plant]
#Change events pictue to that stored in picture
$game_map.events[eventID].character_name = picture.to_s
#Takes the plot to the next stage
$game_farming_plots[plotID][1] += 1
#change self switch b on for the plot
$game_self_switches[[$game_map.map_id, eventID, "B"]] = true
#refresh map so that the changes are shown
$game_map.need_refresh = true
end
if stage == 2
picture = $game_farming_plants_stagetwo[plant]
#Change events pictue to that stored in picture
$game_map.events[eventID].character_name = picture.to_s
#Takes the plot to the next stage
$game_farming_plots[plotID][1] += 1
#change self switch c on for the plot
$game_self_switches[[$game_map.map_id, eventID, "C"]] = true
#refresh map so that the changes are shown
$game_map.need_refresh = true
end
if stage == 3
picture = $game_farming_plants_stagethree[plant]
#Change events pictue to that stored in picture
$game_map.events[eventID].character_name = picture.to_s
#Takes the plot to the next stage
$game_farming_plots[plotID][1] += 1
#change self switch d on for the plot
$game_self_switches[[$game_map.map_id, eventID, "D"]] = true
#refresh map so that the changes are shown
$game_map.need_refresh = true
end
end
end
def self.harvest(plotID)
#Get plant ID
plant = $game_farming_plot[0]
#Gets the exp for growing such plant
exp = $game_farming_plants_exp[plant]
#add the exp to the skill farming (I created a skillbook to keep record of exp and levels and to display this information to the user)
#When the exp is added skillbook also checks if a level should be awarded and that kind of thing
Skillbook.addexp("farrming", exp)
#Resets the plots switches ready for replanting
$game_self_switches[[$game_map.map_id, eventID, "A"]] = false
$game_self_switches[[$game_map.map_id, eventID, "B"]] = false
$game_self_switches[[$game_map.map_id, eventID, "C"]] = false
$game_self_switches[[$game_map.map_id, eventID, "D"]] = false
#clears the plots data ready for reuse and so that it can not cause any issues (Just in case really)
$game_farming_plots[plotID].clear
#sets the item to gain
item = $game_farming_plants_items[plant]
#adds the item nessacry
#$game_items[item].add (I don't know how to do it, but i figured that would show what I planned)
#Sets V6 to the name of the plant recived so that it can be displayed to the player in the textbox
$game_variables[6] = $game_plants_list[plant]
end
end
I am not very good with the commenting or anything script related for that matter. Any help or feedback is appreciated. However being mean or calling me stupid for how badly the script has turned out isn't nice :P.
Also I apologize if this post is in the wrong section.
If you need any more information after reading my commenting please ask, and I will do my best. Thanks everyone!
EDIT
If possible, could someone please test this script for syntax errors? Above when I said the codes that I were given results in syntax errors that doesn't seem to be true. After I added more comments those lines of code have moved down, but I still receive syntax errors on line "34" and "63" which are now comments and not even coding. Would anyone have any idea why this is happening? I have tried copying the script to a new project and have the same result. Could it just be my computer? Thanks again for any help offered