Jump to content


 


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Photo

BASIC question (Generating notepad text)


  • Please log in to reply
3 replies to this topic

#1 Lishy

Lishy

  • Members
  • 49 posts
  • OFFLINE
  •  
  • Local time:10:18 PM

Posted 27 February 2012 - 02:12 AM

Hey guys. I have ZERO programming experience outside of modifying existing works. But some work I'm doing in Doom modding is getting incredibly tedious. I want a program to do it for me.

How can I create a basic program which generates lines of text, adding 1 to whatever value?

To give you a direct example, say I have this:

actor Level12 : Inventory
{
    inventory.amount 0
    inventory.maxamount 1
}

actor Level12Effect : PowerupGiver
{
  inventory.maxamount 0
  powerup.type "Level12EffectPower"
  powerup.duration 9999999
  +AUTOACTIVATE
  states
  {
  Spawn:
    TNT1 A -1
    stop
  }
}

actor PowerLevel12EffectPower : PowerProtection
{
  damagefactor "Bullet", 0.93
  damagefactor "Shotgun", 0.93
  damagefactor "Sniper", 0.93
  damagefactor "Rifle", 0.93
  damagefactor "LMG", 0.93
  damagefactor "BigPistol", 0.93
  damagefactor "Fire", 0.93
  damagefactor "Normal", 0.93
}

I want to make it so it'll generate

actor Level12 : Inventory
{
    inventory.amount 0
    inventory.maxamount 1
}

actor Level12Effect : PowerupGiver
{
  inventory.maxamount 0
  powerup.type "Level12EffectPower"
  powerup.duration 9999999
  +AUTOACTIVATE
  states
  {
  Spawn:
    TNT1 A -1
    stop
  }
}

actor PowerLevel12EffectPower : PowerProtection
{
  damagefactor "Bullet", 0.93
  damagefactor "Shotgun", 0.93
  damagefactor "Sniper", 0.93
  damagefactor "Rifle", 0.93
  damagefactor "LMG", 0.93
  damagefactor "BigPistol", 0.93
  damagefactor "Fire", 0.93
  damagefactor "Normal", 0.93
}

actor Level13 : Inventory
{
    inventory.amount 0
    inventory.maxamount 1
}

actor Level13Effect : PowerupGiver
{
  inventory.maxamount 0
  powerup.type "Level13EffectPower"
  powerup.duration 9999999
  +AUTOACTIVATE
  states
  {
  Spawn:
    TNT1 A -1
    stop
  }
}

actor PowerLevel13EffectPower : PowerProtection
{
  damagefactor "Bullet", 0.93
  damagefactor "Shotgun", 0.93
  damagefactor "Sniper", 0.93
  damagefactor "Rifle", 0.93
  damagefactor "LMG", 0.93
  damagefactor "BigPistol", 0.93
  damagefactor "Fire", 0.93
  damagefactor "Normal", 0.93
}

actor Level14 : Inventory
{
    inventory.amount 0
    inventory.maxamount 1
}

actor Level14Effect : PowerupGiver
{
  inventory.maxamount 0
  powerup.type "Level14EffectPower"
  powerup.duration 9999999
  +AUTOACTIVATE
  states
  {
  Spawn:
    TNT1 A -1
    stop
  }
}

actor PowerLevel14EffectPower : PowerProtection
{
  damagefactor "Bullet", 0.93
  damagefactor "Shotgun", 0.93
  damagefactor "Sniper", 0.93
  damagefactor "Rifle", 0.93
  damagefactor "LMG", 0.93
  damagefactor "BigPistol", 0.93
  damagefactor "Fire", 0.93
  damagefactor "Normal", 0.93
}

And so on...

Basically, taking X and copy pasting it a bunch of times, replacing X with a value added with 1.

How can I make something like this? I would rather personally request that someone make a demonstration program and explain the steps used to create it...

Edited by Lishy, 27 February 2012 - 02:21 AM.


BC AdBot (Login to Remove)

 


#2 groovicus

groovicus

  • Security Colleague
  • 9,963 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Centerville, SD
  • Local time:08:18 PM

Posted 27 February 2012 - 11:14 AM

Honestly I can't think of any way of teaching you that won't take longer than just making the changes by hand. The program itself is trivial, but teaching you how a 'for-loop' works, and how to compile a program in whatever language you choose is not trivial. About the easiest way I can think to do it would be to use a batch script, but they are a bit clunky for this purpose.

#3 Lishy

Lishy
  • Topic Starter

  • Members
  • 49 posts
  • OFFLINE
  •  
  • Local time:10:18 PM

Posted 27 February 2012 - 12:23 PM

Honestly I can't think of any way of teaching you that won't take longer than just making the changes by hand. The program itself is trivial, but teaching you how a 'for-loop' works, and how to compile a program in whatever language you choose is not trivial. About the easiest way I can think to do it would be to use a batch script, but they are a bit clunky for this purpose.


Oh well. I've already filled the notepad up to 50, but I would still like to be taught this.

If anyone here would be so kind, mind making me a .bat and leaving a step by step tutorial with it, or some sort of documentation? I learn best from example! ;)

#4 lanman98

lanman98

  • Members
  • 2 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Arlington Hts, IL
  • Local time:08:18 PM

Posted 28 February 2012 - 04:48 PM

Hi Lishy,

Simple batch scripting can do the trick for you. I have posted two differnet ways that handle your goal. The first one was the easier of the two for me as the FOR... statement takes a little understanding of the syntax. You can just copy/paste this to a .CMD file. Don't copy both samples to the same .CMD file.

Hope this helps your cause.


start of code - sample 1
==============================================================

:start
rem set your starting value here
set /A cnt=1

rem set your ending value here
set stop_cnt=20

rem set your output file here (directory needs be created in advance)
set output_file=c:\temp\sample_output.txt

rem clear output file
echo. > %output_file%

:loop
echo actor Level%cnt% : Inventory >> %output_file%
echo { >> %output_file%
echo inventory.amount 0 >> %output_file%
echo inventory.maxamount 1 >> %output_file%
echo } >> %output_file%
echo. >> %output_file%
echo actor Level1%cnt%Effect : PowerupGiver >> %output_file%
echo { >> %output_file%
echo inventory.maxamount 0 >> %output_file%
echo powerup.type "Level12EffectPower" >> %output_file%
echo powerup.duration 9999999 >> %output_file%
echo +AUTOACTIVATE >> %output_file%
echo states >> %output_file%
echo { >> %output_file%
echo Spawn: >> %output_file%
echo TNT1 A -1 >> %output_file%
echo stop >> %output_file%
echo } >> %output_file%
echo } >> %output_file%
echo. >> %output_file%
echo actor PowerLevel%cnt%EffectPower : PowerProtection >> %output_file%
echo { >> %output_file%
echo damagefactor "Bullet", 0.93 >> %output_file%
echo damagefactor "Shotgun", 0.93 >> %output_file%
echo damagefactor "Sniper", 0.93 >> %output_file%
echo damagefactor "Rifle", 0.93 >> %output_file%
echo damagefactor "LMG", 0.93 >> %output_file%
echo damagefactor "BigPistol", 0.93 >> %output_file%
echo damagefactor "Fire", 0.93 >> %output_file%
echo damagefactor "Normal", 0.93 >> %output_file%
echo } >> %output_file%
echo. >> %output_file%


rem set this number to where you want to stop
if %cnt%==%stop_cnt% goto end
set /A cnt=%cnt% + 1
goto loop

:end
pause
==============================================================
End - sample 1


start of code - sample 2
==============================================================

:start
rem set your starting value here
set /A cnt=1

rem set your ending value here
set stop_cnt=20

rem set your output file here (directory needs be created in advance)
set output_file=c:\temp\sample_output.txt

rem clear output file
echo. > %output_file%

rem FOR /L %%parameter IN (start,step,end) DO command
rem http://ss64.com/nt/for_l.html

FOR /L %%i IN (%cnt%,1,%stop_cnt%) DO (
:loop
echo actor Level%%i : Inventory >> %output_file%
echo { >> %output_file%
echo inventory.amount 0 >> %output_file%
echo inventory.maxamount 1 >> %output_file%
echo } >> %output_file%
echo. >> %output_file%
echo actor Level1%%iEffect : PowerupGiver >> %output_file%
echo { >> %output_file%
echo inventory.maxamount 0 >> %output_file%
echo powerup.type "Level12EffectPower" >> %output_file%
echo powerup.duration 9999999 >> %output_file%
echo +AUTOACTIVATE >> %output_file%
echo states >> %output_file%
echo { >> %output_file%
echo Spawn: >> %output_file%
echo TNT1 A -1 >> %output_file%
echo stop >> %output_file%
echo } >> %output_file%
echo } >> %output_file%
echo. >> %output_file%
echo actor PowerLevel%%iEffectPower : PowerProtection >> %output_file%
echo { >> %output_file%
echo damagefactor "Bullet", 0.93 >> %output_file%
echo damagefactor "Shotgun", 0.93 >> %output_file%
echo damagefactor "Sniper", 0.93 >> %output_file%
echo damagefactor "Rifle", 0.93 >> %output_file%
echo damagefactor "LMG", 0.93 >> %output_file%
echo damagefactor "BigPistol", 0.93 >> %output_file%
echo damagefactor "Fire", 0.93 >> %output_file%
echo damagefactor "Normal", 0.93 >> %output_file%
echo } >> %output_file%
echo. >> %output_file%
echo. >> %output_file%

echo %%i
)

:end
pause
==============================================================
End - sample 2

Edited by lanman98, 28 February 2012 - 05:00 PM.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users