Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Exporting From For Loops
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Guest




PostPosted: 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
Sponsor
sponsor
[Gandalf]




PostPosted: 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




PostPosted: 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 =)
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 3 Posts ]
Jump to:   


Style:  
Search: