NovaProgramming
|
 |
« on: May 04, 2003, 10:54:40 AM » |
|
Hey everybody... I am making an RPG and just recently it is saying something equivalent to: 'out of room' (I can't remember exactly what it said.) So, the help said to break it up into subroutines... well, I have a lot of SUBs, but would adding more SUBs make this help? Also... I know it is possible to DIM multiple variables like this
DIM SHARED flag(10) AS INTEGER
but is there some way to do this:
DIM SHARED item(10) AS STRING
and dim multiple things as strings? Any help would be appreciated.
|
|
|
Logged
|
ovaProgramming. One night I had a dream where I was breaking balls. The next morning, BALLSBREAKER was born. Excellent. Now you can have things without paying for them. BALLSBREAKER 2 ~-_-Status Report-_-~ Engine: 94% Graphics: 95% Sound: 100% A Severe Error has crippled BB2 for the time being... I have to figure it out, but until then you won't see much of it  . -----------------------------
|
|
|
Hard Rock
|
 |
« Reply #1 on: May 04, 2003, 02:23:43 PM » |
|
DIM SHARED item(10) AS STRING
I just copied + pasted your code and it worked fine. So id assume yes. well, I have a lot of SUBs, but would adding more SUBs make this help? Also... I know it is possible to DIM multiple variables like this
If you remove duplicated code by doing so then yes. If not then no.
|
|
|
Logged
|
|
|
|
Meg
|
 |
« Reply #2 on: May 04, 2003, 06:18:08 PM » |
|
You can DIM string as follows: DIM Text$(1 TO 10) this will give you variable-length strings. DIM Text(1 TO 10) AS STRING * n 'n = number of characters in each string this will give you set-length strings. To get rid of the "out of memory" error, you can put code into subroutines, and then put subroutines into modules. There are many tutorials on how to do this. Na_th_an wrote a good one that's floating around this forum someplace. Try the FAQ or doing a search for "modularize" and see what turns up. *peace* Meg.
|
|
|
Logged
|
|
|
|
toonski84
|
 |
« Reply #3 on: May 04, 2003, 06:42:43 PM » |
|
the only thing you can't use varaible-length strings on is in type structures (though you can use fixed length ones).
but yeah, as meg already said, modularize means to split up into files and include them into your program (you need the full version of qb to do this).
|
|
|
Logged
|
i]"I know what you're thinking. Did he fire six shots or only five? Well, to tell you the truth, in all this excitement, I've kinda lost track myself. But being as this is a .44 Magnum ... you've got to ask yourself one question: 'Do I feel lucky?' Well, do ya punk?"[/i] - Dirty Harry
|
|
|
NovaProgramming
|
 |
« Reply #4 on: May 05, 2003, 01:56:24 PM » |
|
So does that mean that this would *not* work? DIM SHARED item(10) AS STRING
item(1)$ = "Hat" item(2)$ = "Sword" item(3)$ = "NOTHING"
because if that would work I would be able to dramatically downsize the length of some of my code... I am using strings that take up a lot of space... item1$ item2$ ... item10$ so if this item(n)$ were to work it would make my life easier... thus I could do something like for i = 1 to 10 if item(i)$ = "NOTHING" then item(i)$ = "Hat": goto endit next i print "There is no open slot..." endit:
|
|
|
Logged
|
ovaProgramming. One night I had a dream where I was breaking balls. The next morning, BALLSBREAKER was born. Excellent. Now you can have things without paying for them. BALLSBREAKER 2 ~-_-Status Report-_-~ Engine: 94% Graphics: 95% Sound: 100% A Severe Error has crippled BB2 for the time being... I have to figure it out, but until then you won't see much of it  . -----------------------------
|
|
|
Aaron
Member

Posts: 35
|
 |
« Reply #5 on: May 05, 2003, 02:54:01 PM » |
|
actually, that code would work fine
|
|
|
Logged
|
|
|
|
Meg
|
 |
« Reply #6 on: May 05, 2003, 03:23:22 PM » |
|
Yes, you can use arrays of strings. However, they look like this:
Item$(n)
not
Item(n)$
*peace*
Meg.
|
|
|
Logged
|
|
|
|
Meg
|
 |
« Reply #7 on: May 05, 2003, 03:38:21 PM » |
|
There are many ways in which you can cut down on the size of your code. I *HIGHLY* recommend putting all item-handling code into subroutines. If you are not sure how to do this, follow this: DIM SHARED Inventory$(0 to 9) 'make a 10-item inventory that can be accessed by subroutines
CALL ListInventory 'this will display your inventory on the screen CALL AddItemToInventory("Hat") 'this will add a hat to your inventory CALL DropItemFromInventory(3) 'this will drop whatever item is in spot 3 of your inventory.
END 'end the program
'=========== SUBROUTINES GO AFTER PROGRAM ENDING =========== '==== (or sometimes in their own window, depending on QB version) =====
SUB ListInventory PRINT "You are carrying the following items:" PRINT "-------------------------------------" FOR i = 0 TO 9 'loop through all inventory slots PRINT i; " - " + Inventory$(i) EXIT i END SUB
SUB AddItemToInventory (NewItem$) spot = -1 FOR i = 9 TO 0 STEP -1 'find the first open slot in inventory IF Inventory$(i) = "" THEN spot = i NEXT i
IF spot = -1 THEN 'no slots were open PRINT "You can't carry any more items! Drop something first!" ELSE 'a slot was open PRINT "You pick up the item and put it in your pack." Inventory$(spot) = NewItem$ END IF END SUB
SUB DropItemFromInventory (DropThisNumber) IF Inventory$(DropThisNumber) = "" THEN 'nothing to drop! PRINT "You aren't carrying an item in that slot!" ELSE 'something to drop PRINT "You drop the " + Inventory$(DropThisNumber) + "on the gruond." Inventory$(DropThisNumber) = "" END IF END SUB
I hope this makes sense and that I don't have any typos/logic errors. Let me know if you have any questions. *peace* Meg.
|
|
|
Logged
|
|
|
|
Aaron
Member

Posts: 35
|
 |
« Reply #8 on: May 05, 2003, 05:35:16 PM » |
|
oops, Meg is right, I didn't even see that you had the type delineator on the wrong side of the subscript
|
|
|
Logged
|
|
|
|
Meg
|
 |
« Reply #9 on: May 08, 2003, 12:29:07 AM » |
|
oops, Meg is right, I didn't even see that you had the type delineator on the wrong side of the subscript Oh my. That comment just made me realize how much of a total dork I am. *peace* Meg.
|
|
|
Logged
|
|
|
|
NovaProgramming
|
 |
« Reply #10 on: May 08, 2003, 01:58:20 PM » |
|
Thanks everybody.. I think that the item$(n) will work a lot better then doing if item$ = "" then... for item1$-item10$.... yeah, well, thanks! this will help a lot!
|
|
|
Logged
|
ovaProgramming. One night I had a dream where I was breaking balls. The next morning, BALLSBREAKER was born. Excellent. Now you can have things without paying for them. BALLSBREAKER 2 ~-_-Status Report-_-~ Engine: 94% Graphics: 95% Sound: 100% A Severe Error has crippled BB2 for the time being... I have to figure it out, but until then you won't see much of it  . -----------------------------
|
|
|
|