You are not logged in.

#1 01 Jun 2006 07:54

NDog
Member
From: New Zealand
Registered: 31 May 2006
Posts: 121
Website

Overbloated GOTO section needs tightening, please help

Okay this is an annoying over bloated section of my script, the rest of the script is not here, but it is working fine

In essence this is a cd key changer script, which works by the server distributing a file called game.1, game.2, game.3, up to game.8 to a localfolder.

What i want to happen: if game.3 exists in the localfolder, the script needs to retrieve 3, then it needs to set key=key3

Also there will only be one copy of a game.number file at any time in the localfolder, so dont worry about more than one file smile

If anyone can help me to shorten this script i will be happy, thanks in advance

Current Script (overbloated it does work, but im not too happy with the length)

REM    ========================================================
REM    CD KEYS CD KEY STORAGE
REM    ========================================================
    SET KEY1=user1 pass1
    SET KEY2=user2 pass2
    SET KEY3=user3 pass3
    SET KEY4=user4 pass4
    SET KEY5=user5 pass5
    SET KEY6=user6 pass6
    SET KEY7=user7 pass7
    SET KEY8=user8 pass8

REM    ========================================================
REM    CD KEYS CD KEY CHANGER
REM    ========================================================

    CD /D "%LOCALFOLDER%"
   
    IF EXIST "%LOCALFOLDER%\%GAME%.1" GOTO KEY1
    IF EXIST "%LOCALFOLDER%\%GAME%.2" GOTO KEY2
    IF EXIST "%LOCALFOLDER%\%GAME%.3" GOTO KEY3
    IF EXIST "%LOCALFOLDER%\%GAME%.4" GOTO KEY4
    IF EXIST "%LOCALFOLDER%\%GAME%.5" GOTO KEY5
    IF EXIST "%LOCALFOLDER%\%GAME%.6" GOTO KEY6
    IF EXIST "%LOCALFOLDER%\%GAME%.7" GOTO KEY7
    IF EXIST "%LOCALFOLDER%\%GAME%.8" GOTO KEY8

    :KEY1
    SET KEY=%KEY1%
    GOTO LOADER
    :KEY2
    SET KEY=%KEY2%
    GOTO LOADER
    :KEY3
    SET KEY=%KEY3%
    GOTO LOADER
    :KEY4
    SET KEY=%KEY4%
    GOTO LOADER
    :KEY5
    SET KEY=%KEY5%
    GOTO LOADER
    :KEY6
    SET KEY=%KEY6%
    GOTO LOADER
    :KEY7
    SET KEY=%KEY7%
    GOTO LOADER
    :KEY8
    SET KEY=%KEY8%
    GOTO LOADER

:LOADER
rest of the script goes here


cmd, vbs, ps, bash
autoit, python, swift

Offline

#2 01 Jun 2006 19:37

Simon Sheppard
Admin
Registered: 27 Aug 2005
Posts: 1,130
Website

Re: Overbloated GOTO section needs tightening, please help

IF EXIST "%LOCALFOLDER%\%GAME%.1" SET KEY=%KEY1% &GOTO LOADER
IF EXIST "%LOCALFOLDER%\%GAME%.2" SET KEY=%KEY2% &GOTO LOADER
...

Offline

#3 02 Jun 2006 02:33

NDog
Member
From: New Zealand
Registered: 31 May 2006
Posts: 121
Website

Re: Overbloated GOTO section needs tightening, please help

I didnt realise you could use & to continue the same line, I re-edited my code now it works fine, thanks!


cmd, vbs, ps, bash
autoit, python, swift

Offline

Board footer

Powered by