Exporting From For Loops
Author |
Message |
Guest
|
Posted: Fri Jun 02, 2006 10:46 pm Post subject: Exporting From For Loops |
|
|
In one of my modules, I have it export var all, but it doesn't export what is modified in my for loop. My teacher reminded me that everything in a for loop is only seen in the for loop. How do I send data from my for loop outside of the for loop.
code: |
unit
module Characters
export var all
%This module stores all main character pictures.
var VAHN_DIR : int
var dir := "DATA/SPRITES/CHARACTERS/"
const VAHN_BATTLE := Pic.FileNew (dir + "BATTLE_VAHN.jpg")
const VAHN_PICTURE := Pic.FileNew (dir + "PICTURE_VAHN.jpg")
%changes picture direction accordingly
%uses for loop for frames
for i : 1 .. 3
var VAHN_DIR_FORWARD_i := Pic.FileNew (dir + "VAHN_FORWARD_" + intstr (i) + ".bmp")
var VAHN_DIR_BACKWARD_i := Pic.FileNew (dir + "VAHN_BACKWARD_" + intstr (i) + ".bmp")
var VAHN_DIR_LEFT_i := Pic.FileNew (dir + "VAHN_LEFT_" + intstr (i) + ".bmp")
var VAHN_DIR_RIGHT_i := Pic.FileNew (dir + "VAHN_RIGHT_" + intstr (i) + ".bmp")
VAHN_DIR := VAHN_DIR_FORWARD_i %default position of Vahn
end for
put "Loading character models..."
put "Character models were successfully imported!"
put "Loading monster models..."
end Characters
|
How am I able to export this? In my main program it gives me 4 errors: "VAHN_DIR_(direction)_1" is not in the export list of 'Characters'" |
|
|
|
|
|
Sponsor Sponsor
|
|
|
[Gandalf]
|
Posted: Fri Jun 02, 2006 11:21 pm Post subject: (No subject) |
|
|
Exporting all will only export the variables in the whole scope of the module. As your teacher said, the variables in the for loop only exist there, not within the whole module, so they do not get exported. To include them with all you must declare them outside the for loop as you have done with VAHN_BATTLE, and initialize them inside it.
Your usage of the module is not great either... You are using it to compartmentalize your code, which could be done with a procedure. Your module should contain procedures (and functions), some of which will be exported to allow access of the module from the outside world. |
|
|
|
|
|
Guest
|
Posted: Sat Jun 03, 2006 11:03 am Post subject: (No subject) |
|
|
Well I learned Modules recently, so I tried to organize my code. Really, there was no need for me to add modules at all, but when I hand it in for my ISU im hoping to get a good mark for using them. I'm not sure if the teacher uses modules, so that's a good sign =) |
|
|
|
|
|
|
|