Executing one Turing File from another
Author |
Message |
MichaelM
|
Posted: Sun Aug 12, 2007 11:28 am Post subject: Executing one Turing File from another |
|
|
Im was working on an RPG, and to start I made the main game (walking around etc.) and the battle system in different files. I am now at the point where I want to put them together, to make random battles etc. My plan was to make the whole battle program into a procedure using enemy type, enemy HP and so on as the parameters. However, this is giving me problems:
-outside varialbes such as your HP and other attributes are not being imported
-also, the battle program has procedures of its own, so theres a million errors that say:
"procedure's may only be declared at the program, module, or monitor level"
So I see two possibilities that both give me problems. First, to make the battle program a procedure, use every variable I'll need as a parameter, but then theres still the problem of "procedure's may only be declared..." bla bla bla
Then I thought, maybe I could just run/execute my battle program from the main game whenever I wanted a battle to occur.
Is there anyone who could give me help as to which method will work, if any, and how to do it? Or maybe a link to a tutorial that will help (I couldn't find one)
thanks!
PS - Im not sure if it will effect the way I fix this problem, but just so you know, I only have Turing 3.1.1A or something like that |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Nick
|
Posted: Sun Aug 12, 2007 3:04 pm Post subject: Re: Executing one Turing File from another |
|
|
ok as far as i can tell your importing your battle right but im not sure if your exporting right...
this is what it should look like:
unit
module battle
import hp,maxhp,enemyhp,enemyMaxhp,other vars
export all procedures
enemy atack
declare inbattle vars here
end enemy attack
then ur main program
import ("other thing")
export all your battle vars
and that should work
also be sure ur using the battle.enemy attack instead of something like
battle or just enemy attack
im using the same format for my game execpt the battles are in the main program but the cutscenes are bing imported so ive hit my computer severeal times over this... good luck |
|
|
|
|
|
Clayton
|
Posted: Sun Aug 12, 2007 7:13 pm Post subject: RE:Executing one Turing File from another |
|
|
Could we see some code? I have a funny feeling I know what your problem is, but it's kind of difficult to explain without seeing your code. |
|
|
|
|
|
MichaelM
|
Posted: Mon Aug 13, 2007 10:42 am Post subject: Re: Executing one Turing File from another |
|
|
Okay heres some of the code for the battle, but Im asuming you don't want to see all 400 lines of it, and I'm afraid you wont be able to run it because it involves some battle animations using .bmps that you wont have, but take a look
This is only the procedures for drawing your stats, your normal attack move, and the enemy's normal attack move.
and in case your wondering, all the areas with delays and things like e_g1(x,y) are the animations. I also left out most variables
code: |
setscreen("graphics:400;400")
drawline(0,60,400,60,black)
drawline(0,295,400,295,black)
var battlesummary:= GUI.CreateTextBoxFull (10, 305, 380, 85, GUI.INDENT, 0)
b_back(225,100)
e_g1(100,200)
procedure stats(h,p:int)
tempHP:=tempHP-h
if tempHP<=0 then
b_down(260,95)
GUI.AddText (battlesummary,name)
GUI.AddText (battlesummary," was felled!")
GUI.AddLine (battlesummary, "")
tempHP:=0
end if
var HPc:int:=2
if tempHP<(HP div 2) then
HPc:=14
end if
if tempHP<(HP div 5) then
HPc:=12
end if
var percentageHP:real:=0
percentageHP:=tempHP/HP
var full:int:=144
drawfillbox(0,0,200,50,white)
locatexy(0,32)put tempHP..
put "/",HP
put tempPP..
put "/",PP
var HPdraw:real:=0
HPdraw:=full*percentageHP
drawfillbox(48,30,floor(HPdraw)+48,38,HPc)
drawbox(48,30,192,38,black)
drawbox(49,31,192-1,37,black)
drawfillbox(48,18,192,26,green)
drawbox(48,18,192,26,black)
drawbox(49,19,192-1,25,black)
end stats
stats(0,0)
procedure e_attack
delay(500)
sound(494,60)
e_g1(105,195)
delay(200)
e_g2(105,195)
delay(200)
e_g1(105,195)
b_hit(225,100)
delay(200)
e_g1(100,200)
delay(200)
b_back(225,100)
var h:int
var e_luckyhit:int:=0
var a:int:=0
for x:0..e_Luck
randint(h,1,50)
if h=e_Luck then
e_luckyhit:=ceil(e_Attack*.25)
end if
end for
a:=e_Attack
a:=a-ceil(Defense*.33)+e_luckyhit
GUI.AddText (battlesummary,e_name)
GUI.AddText (battlesummary," does ")
GUI.AddText (battlesummary,intstr(a))
GUI.AddText (battlesummary," damage!")
GUI.AddLine (battlesummary, "")
stats(a,0)
end e_attack
procedure attack
sound(313,60)
var h:int
var luckyhit:int:=0
var a:int:=0
for x:0..Luck
randint(h,1,50)
if h=Luck then
luckyhit:=ceil(Attack*.25)
end if
end for
a:=Attack
a:=a-ceil(e_Defense*.33)+luckyhit
b_a1(225,110)
delay(500)
b_a2(225,95)
delay(500)
b_back(225,100)
GUI.AddText (battlesummary,name)
GUI.AddText (battlesummary," does ")
GUI.AddText (battlesummary,intstr(a))
GUI.AddText (battlesummary," damage!")
GUI.AddLine (battlesummary, "")
delay(200)
e_HP:=e_HP-a
if e_HP>0 then
e_attack
elsif e_HP<=0 then
e_g3(95,205)
delay(300)
GUI.AddText (battlesummary,e_name)
GUI.AddText (battlesummary," was felled!")
GUI.AddLine (battlesummary, "")
drawfillbox(95,205,130,255,white)
end if
end attack
|
Hope that helps you understand, If you really want it, I could post/email you the whole file with pic files |
|
|
|
|
|
Nick
|
Posted: Mon Aug 13, 2007 11:20 am Post subject: RE:Executing one Turing File from another |
|
|
you said this was to be imported into the main game but im not seeing any exports not imports in the code... im not sure if you took them out or not but if not then "theres your problem" |
|
|
|
|
|
Saveron
|
Posted: Mon Aug 13, 2007 1:34 pm Post subject: Re: Executing one Turing File from another |
|
|
This doesn't look like a module to me, so u don't use import/export. In the main program add in the line
include (the location and name of your program)
for example:
include "procedures/battlesystem.t"
you can put the include anywhere you want in your program so put it where it doesn't make errors. This is usually after your main program's declarations.[/syntax] |
|
|
|
|
|
Nick
|
Posted: Mon Aug 13, 2007 2:10 pm Post subject: RE:Executing one Turing File from another |
|
|
oh thats a better way than using modules... depending on what ur doing thanks for the tip ^_^ |
|
|
|
|
|
Clayton
|
Posted: Wed Aug 15, 2007 7:45 pm Post subject: RE:Executing one Turing File from another |
|
|
Well... it is and it isn't. If you're using a gazillion global variables, then things become retardedly messy extremely fast. This is why myself and others stress so strongly that you compartmentalize and use as few global variables as possible. As a side note, that is one of the reasons I love functional programming so much |
|
|
|
|
|
Sponsor Sponsor
|
|
|
MichaelM
|
Posted: Thu Aug 16, 2007 4:44 pm Post subject: Re: Executing one Turing File from another |
|
|
or would it work to change the variables I need into constants, and maybe then they will be imported, or would that make things more messed up? I'll give it a try, but then theres still the issue of the procedures not working...
--edit--
okay, so the constant idea wont work for what I want to do, since they will be changed. However I tried making it a module, and that solves many problems while making some others. now theres messages about failing to import GUIs. So now the question is, can I or how do I import GUIs into a module?
the follwoing did not work
code: |
import GUI in "%oot/lib/GUI"
|
it highlights the word "in" as a syntax error
--edit--
nevermind with the GUI problem, I just figured out that all i needed was
I guess I thought it would be more complicated than that |
|
|
|
|
|
Nick
|
Posted: Fri Aug 17, 2007 3:56 pm Post subject: RE:Executing one Turing File from another |
|
|
lol simplicity is sometimes more complex than complexity... word for thought |
|
|
|
|
|
|
|