# cmd to many variables lag ?



## vista_narvas (Nov 6, 2012)

does to many variables slow cmd down?
or maybe the size of the batch file?
im working on a game that has 41*19*99 variables (only for the 99 levels)
but the game is starting to lag
it only lags when i need to echo 779 variables and does not lag when i echo something else
when using 41*19 variables i dont have lag
is there a way to ignore the other variables or something
i dont like to set and load em to a file while playing
but if there is no other way ill do that
but i still need all the 77121 variables


----------



## foxidrive (Oct 20, 2012)

If we can see the code with the problem then maybe there are some optimisations that could be done.


----------



## vista_narvas (Nov 6, 2012)

its to big to post here
this is the zip


----------



## Squashman (Apr 4, 2003)

yes it will slow down as the environment grows and will slow down when using CALLS and goto other functions. We just had this discussion not to long ago on another forum that foxidrive and I belong too.


----------



## vista_narvas (Nov 6, 2012)

is there a way to delete a variable?
so i can export the variables from the level to its own file
than delete the variables
and load the file when entering a level


----------



## Squashman (Apr 4, 2003)

vista_narvas said:


> is there a way to delete a variable?




```
Set var=squashman
Echo %var%
Set var=
Echo %var%
```


----------



## foxidrive (Oct 20, 2012)

Here's another version attached. It gets rid of much of the duplication - and should function as your original code does.

I might have introduced some errors but have a look anyway and see if it appeals to you.

You call: levelup after changing %curlevel% and it should adjust the level variables.

I've uploaded the changed version as adventure4.zip attachment

Press L at the map to increase the level - I didn't change any of the maps so only level 1 changes.


----------



## vista_narvas (Nov 6, 2012)

0.o

the lag is gone
but i have no idea what you did and how it works
but i think it doesn't safe the level when you go to the next level
so if you go back everything is like the original and not the stuff you dropped and build
i had

```
:nextlevel
set N00-%curlevel%=%N00%
set N01-%curlevel%=%N01%
etc
```
to fix that
but i have no idea how to do that now


----------



## foxidrive (Oct 20, 2012)

I broke the inventary when I fixed what I assumed was a typo.

replace all of these :inverary with :inventary

Does that fix it?

This section

:nextlevel
set N00-%curlevel%=%N00%
set N01-%curlevel%=%N01%
etc

 
should be the same as this

:nextlevel
for /L %%a in (0,1,820) do (
set N0%%a-%curlevel%=!N0%%a!
)


----------



## foxidrive (Oct 20, 2012)

I don't understand everything about your code

For instance, the variables from 779 to 820 in each level. Are they used for some purpose?


----------



## foxidrive (Oct 20, 2012)

Here's a bit of explanation of how I changed the level system

Firstly, at the top of the batch file is setlocal enabledelayedexpansion
and that operates over the whole batch file.

Then there is a set of variables with set level-0= and set level-1= etc.

The line below (it is only one line) sets level-0 and it is every pixel from 0 to 778

set level-0=#NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN##---------------------------------------E#---------------------------------------E#---------------------------------------E#---------------------------------------E#---------------------------------------E#--------------ÉÍÍÍÍÍÍÍ»----------------E#--------------º-------º----------------E#--------------º-------Ð----------------E#---ÉÍÍÍÍÍÍÍÍÍÍ¹------------------------E#---ºß--8°°---ßº-------Ò----------------E#---º----°°----º-------º----------------E#---º----------º-------º----------------E#---ÌÍÍDÍÍÍÍÍÍÍÊÍÍÍÍÍÍÍ¹----------------E#---º------------------º----------------E#---º------------------D----------------E#---º[]----------------º----------------E#---ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ¼----------------E#########################################


This line calls the subroutine to populate the N00-0= and N01-0= variables etc from level-0

call :level 0

and this subroutine at the very bottom can set all of the pixel variables (N00-0 etc), to all level maps, from level-0 and level-1 etc, but it only sets one level at a time... which is far faster. It's used to go to different maps/levels.

:level
@echo off
set pixel=-1
set "characters=!level-%1!"
for /L %%b in (0,1,778) do (
set /a pixel=pixel+1
set "N0!pixel!-%1=!characters:~%%b,1!"
)

I hope that explains some of the changes.


----------



## vista_narvas (Nov 6, 2012)

foxidrive said:


> I don't understand everything about your code
> 
> For instance, the variables from 779 to 820 in each level. Are they used for some purpose?


779 to 820 are probably the variables from when i was trying different size in screen



foxidrive said:


> Here's a bit of explanation of how I changed the level system
> 
> Firstly, at the top of the batch file is setlocal enabledelayedexpansion
> and that operates over the whole batch file.
> ...


what happens now when you go to the next level is you only go to the next level
is it possible to safe all the variables from the map to the current level and than go to the next level?


----------



## foxidrive (Oct 20, 2012)

Do you mean that the items you get on one map are taken away on the next map, and when you go back to the first map the items magically reappear?

I thought that once you pick up an item it remains in your possession until you lose it or use it.

Please explain how this works and I'll see what I can do.


----------



## vista_narvas (Nov 6, 2012)

when you place or break something and after that go to the next level and go back than its gone (or back if you broke something)


----------



## foxidrive (Oct 20, 2012)

Can you answer my question? It seems like you want everything to reappear when you go back to an old map.


----------



## vista_narvas (Nov 6, 2012)

no i like to have everything like you leaved


----------



## foxidrive (Oct 20, 2012)

You are saying no, but then you say you want the items to be how they were when you left the map, or I don't understand how you are phrasing this,

Does that mean that everything disappears when you go to a new map?


----------



## foxidrive (Oct 20, 2012)

I think I know what you mean - your routine :nextlevel doesn't take you to the next level, it stores the state of each map in memory. Say, if you chop a tree down and the tree disappears, when you go back to the same map then the tree should not be there.

That has nothing to do with the items in your inventary...

But what should happen if the player exits the game? Should it remember where he is and the state of every map?


----------



## foxidrive (Oct 20, 2012)

By the way. I spelled inventory wrong too.


----------



## vista_narvas (Nov 6, 2012)

foxidrive said:


> By the way. I spelled inventory wrong too.


lol i spell everything wrong

but the inv is not the problem
here i placed a block

```
#NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN#
#---------------------------------------E
#---------------------------------------E
#---------------------------------------E
#---------------------------------------E
#---------------------------------------E
#--------------&#9556;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9559;----------------E
#--------------&#9553;-------&#9553;----------------E
#--------------&#9553;-------&#9576;----------------E
#---&#9556;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9571;----------------&#9574;-------E
#---&#9553;&#9600;---&#9617;&#9617;---&#9600;&#9553;-------&#9573;---------8------E
#---&#9553;----&#9617;&#9617;----&#9553;-------&#9553;----------------E
#---&#9553;----------&#9553;-------&#9553;----------------E
#---&#9568;&#9552;&#9552;D&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9577;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9571;----------------E
#---&#9553;------------------&#9553;----------------E
#---&#9553;------------------D----------------E
#---&#9553;[-]---------------&#9553;----------------E
#---&#9562;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9565;----------------E
#########################################
```
and if i go to a other level and back 

```
#NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN#
#---------------------------------------E
#---------------------------------------E
#---------------------------------------E
#---------------------------------------E
#---------------------------------------E
#--------------&#9556;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9559;----------------E
#--------------&#9553;-------&#9553;----------------E
#--------------&#9553;-------&#9576;----------------E
#---&#9556;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9571;------------------------E
#---&#9553;&#9600;--8&#9617;&#9617;---&#9600;&#9553;-------&#9573;----------------E
#---&#9553;----&#9617;&#9617;----&#9553;-------&#9553;----------------E
#---&#9553;----------&#9553;-------&#9553;----------------E
#---&#9568;&#9552;&#9552;D&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9577;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9571;----------------E
#---&#9553;------------------&#9553;----------------E
#---&#9553;------------------D----------------E
#---&#9553;[-]---------------&#9553;----------------E
#---&#9562;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9565;----------------E
#########################################
```
the block i placed is gone( and the 8 where you start is in side the house and the player is gone (but i think that is a bug that i made))


----------



## vista_narvas (Nov 6, 2012)

that dint work out


----------



## vista_narvas (Nov 6, 2012)

before








after


----------



## Squashman (Apr 4, 2003)

vista_narvas said:


> that dint work out


The site admin screwed up the CODE tags a few months ago. I expressed my concerns about it but he believe what he did was the correct way to do it.

I you put it inside quote tags it should look correctly other than the mono spacing.


----------



## foxidrive (Oct 20, 2012)

A problem with updating all maps when changing screens is that you have to keep them all in ram, which means the delay while they are read is unavoidable.


----------



## vista_narvas (Nov 6, 2012)

but you update only 1 map when going to the next room


----------

