Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Random  (Read 9571 times)

0 Members and 1 Guest are viewing this topic.

Helpmeh

    Topic Starter


    Guru

  • Roar.
  • Thanked: 123
    • Yes
    • Yes
  • Computer: Specs
  • Experience: Familiar
  • OS: Windows 8
Random
« on: October 11, 2008, 08:01:16 AM »
I need some help with the %random% function. I need a random number between 0 and 100 and I've tried a couple ways, but they just create a random number(above 100). I've seen a couple other threads like this, but it all went WAY above my head. If you can, explain it line-by-line please.


The fruits of my labour!

http://www.megaupload.com/?d=DUA8211C
MONSTER BATTLE 0.1!
« Last Edit: October 11, 2008, 10:38:59 AM by Helpmeh »
Where's MagicSpeed?
Quote from: 'matt'
He's playing a game called IRL. Great graphics, *censored* gameplay.

Carbon Dudeoxide

  • Global Moderator

  • Mastermind
  • Thanked: 169
    • Yes
    • Yes
    • Yes
  • Certifications: List
  • Experience: Guru
  • OS: Mac OS
Re: Random
« Reply #1 on: October 11, 2008, 08:03:54 AM »
Here is a snippet from one of my earlier batch programs

set /a number=(%Random% %%100)+1

Try that.

Helpmeh

    Topic Starter


    Guru

  • Roar.
  • Thanked: 123
    • Yes
    • Yes
  • Computer: Specs
  • Experience: Familiar
  • OS: Windows 8
Re: Random
« Reply #2 on: October 11, 2008, 08:07:42 AM »
Thanks! Works great! :D
Where's MagicSpeed?
Quote from: 'matt'
He's playing a game called IRL. Great graphics, *censored* gameplay.

Carbon Dudeoxide

  • Global Moderator

  • Mastermind
  • Thanked: 169
    • Yes
    • Yes
    • Yes
  • Certifications: List
  • Experience: Guru
  • OS: Mac OS
Re: Random
« Reply #3 on: October 11, 2008, 08:08:13 AM »
 :)

Helpmeh

    Topic Starter


    Guru

  • Roar.
  • Thanked: 123
    • Yes
    • Yes
  • Computer: Specs
  • Experience: Familiar
  • OS: Windows 8
Re: Random
« Reply #4 on: October 11, 2008, 08:30:19 AM »
Now it's just repeating...so much for random :(
Where's MagicSpeed?
Quote from: 'matt'
He's playing a game called IRL. Great graphics, *censored* gameplay.

Carbon Dudeoxide

  • Global Moderator

  • Mastermind
  • Thanked: 169
    • Yes
    • Yes
    • Yes
  • Certifications: List
  • Experience: Guru
  • OS: Mac OS
Re: Random
« Reply #5 on: October 11, 2008, 08:31:48 AM »
Not working properly?

What is your code so far?

Helpmeh

    Topic Starter


    Guru

  • Roar.
  • Thanked: 123
    • Yes
    • Yes
  • Computer: Specs
  • Experience: Familiar
  • OS: Windows 8
Re: Random
« Reply #6 on: October 11, 2008, 08:40:06 AM »
Well it's wierd. The PvComp thing I saw on youtube looked cool...I thought I could sorta make a simmilar thing. Here it is:
Code: [Select]
@echo off
if not exist mhpfile echo 100 > mhpfile
if not exist phpfile echo 100 > phpfile
set /a mdmg=(%Random% %%20)+1
set /a pdmg=(%Random% %%20)+1
set /p mhp=<mhpfile
set /p php=<phpfile
Echo [Monster Health] %mhp%
Echo.
Echo.
Echo [Your    Health] %php%
pause
cls
Echo [Monster Health] %mhp%
Echo.
Echo.
Echo [Your    Health] %php%
:attack
Echo Attack?
set /p att1=Y/N
if %att1%=='Y' goto att1
if %att1%=='y' goto att1
if %att1%=='N' goto exit
if %att1%=='n' goto exit
:exit
exit
:att1
cls
Echo [Monster Health] %mhp%
Echo [Monster Attack] %mdmg%
Echo.
Echo.
Echo [Your    Health] %php%
Echo [Your    Attack] %pdmg%
pause
set /a mhp=(%mhp%-%pdmg%)
set /a php=(%php%-%mdmg%)
Echo [Monster Health] %mhp%
echo.
echo.
Echo [Your    Health] %php%
goto attack
pause

For some reason, it is random the first time, but keeps using the same numbers for the rest. >:(
Where's MagicSpeed?
Quote from: 'matt'
He's playing a game called IRL. Great graphics, *censored* gameplay.

Jacob



    Hopeful

    Thanked: 1
    • Experience: Expert
    • OS: Windows XP
    Re: Random
    « Reply #7 on: October 11, 2008, 08:50:52 AM »
    You can download the whole of AOA basic including PvComp.
     Here is the file (note: it will not run because thing need to be declared)
    Notice:
    Code: [Select]
    set /a OppDamage=%random%%%%OAttack%-29
    set /a Damage=%random%%%%Attack%-29

    here is the full PvComp
    Code: [Select]
    ::    ___                       ____  ____   ___       __                 __               
    ::   /   |  ________  ____ _   / __ \/ __/  /   | ____/ /   _____  ____  / /___  __________
    ::  / /| | / ___/ _ \/ __ `/  / / / / /_   / /| |/ __  / | / / _ \/ __ \/ __/ / / / ___/ _ \
    :: / ___ |/ /  /  __/ /_/ /  / /_/ / __/  / ___ / /_/ /| |/ /  __/ / / / /_/ /_/ / /  /  __/
    ::/_/  |_/_/   \___/\____/   \____/_/    /_/  |_\__,_/ |___/\___/_/ /_/\__/\____/_/   \___/
    ::---------------------------------------------------------------------------------------------
    ::                                          The most advanced microsoft ms-dos batch game ever.
    ::---------------------------------------------------------------------------------------------
    ::
    ::Created By: Jacob
    ::Date: 13/09/08
    ::File Name: PvComp
    @echo off
    :start
    COLOR 07
    title %AccName% - %Target%
    :Combat

    set /a OppDamage=%random%%%%OAttack%-29
    set /a Damage=%random%%%%Attack%-29

    If %OppDamage% LSS 0 (
    set OppDamage=0
    )

    If %Damage% LSS 0 (
    set Damage=0
    )

    set /a SpecChance=(%random%*%specratio%/32767)
    If %SpecChance%==0 (
    set s=Yes
    set /a nos=%nos%+1
    set /a Damage=%Damage%+%random%%%%Attack%
    ) else (
    set s=No
    )

    set /a OSpecChance=(%random%*%Ospecratio%/32767)
    If %OSpecChance%==0 (
    set os=Yes
    set /a onos=%onos%+1
    set /a OppDamage=%OppDamage%+%random%%%%OAttack%
    ) else (
    set os=No
    )

    ::Max Hit Calculation
    ::
    If %Damage% GTR %Mhit% (
    set Mhit=%Damage%
    )
    If %OppDamage% GTR %OMhit% (
    set OMhit=%OppDamage%
    )
    ::
    ::

    set /a CHealth=%CHealth%-%OppDamage%
    set /a OCHealth=%OCHealth%-%Damage%

    echo [Combat PvComp beta] [Written By: Jacob]
    echo.
    echo [Name: %AccName%] [Health: %CHealth%/%MHealth%] [Attack: %Attack%] [Level: %lvl%]
    echo [Hit: %Damage%]
    If %s%==Yes (
    echo [Special Attack]
    )
    echo.
    echo [Name: %Target%] [Health: %OCHealth%/%OMHealth%] [Attack: %OAttack%] [Level: %Opplvl%]
    echo [Hit: %OppDamage%]
    If %os%==Yes (
    echo [Special Attack]
    )

    ping 127.0.0.1 -n 2 > NUL
    ping 127.0.0.1 -n 2 > NUL

    If %CHealth% LEQ 0 (
    set Result=Lost
    goto YouLost
    )
    If %OCHealth% LEQ 0 (
    set Result=Won
    goto YouWin
    )

    cls

    ::LOOP
    goto start


    :YouWin
    set /a UID=%random%*%random%
    If Not Exist data\fights (
    md data\fights
    )
    If exist data\fights\%UID%.txt (
    goto YouWin
    )
    echo %AccName% %Result% Against The %Target%.>data\fights\%UID%.txt
    echo.>>data\fights\%UID%.txt
    echo  You [%Result%] The Fight.>>data\fights\%UID%.txt
    echo  You Banished, The %Target% To The Underworld.>>data\fights\%UID%.txt
    echo.>>data\fights\%UID%.txt
    echo  Your Max Hit Was: [%Mhit%].>>data\fights\%UID%.txt
    echo  You Did [%nos%] Special Attacks.>>data\fights\%UID%.txt
    echo  Your Finishing Health Was: [%CHealth%/%MHealth%].>>data\fights\%UID%.txt
    echo.>>data\fights\%UID%.txt
    echo  Your Opponents Max Hit Was: [%OMhit%].>>data\fights\%UID%.txt
    echo  Your Opponent Did [%onos%] Special Attacks.>>data\fights\%UID%.txt
    echo  Your Opponents Finishing Health Was: [%OCHealth%/%OMHealth%].>>data\fights\%UID%.txt
    cls
    echo.
    echo  [Fight Summary]
    echo.
    echo  You [%Result%] The Fight.
    echo  You Banished, The %Target% To The Underworld.
    echo.
    echo  Your Max Hit Was: [%Mhit%].
    echo  You Did [%nos%] Special Attacks.
    echo  Your Finishing Health Was: [%CHealth%/%MHealth%].
    echo.
    echo  Your Opponents Max Hit Was: [%OMhit%].
    echo  Your Opponent Did [%onos%] Special Attacks.
    echo  Your Opponents Finishing Health Was: [%OCHealth%/%OMHealth%].
    echo.
    echo.
    echo.
    echo  UID: [%UID%]
    pause >nul
    exit
    :YouLost
    set /a UID=%random%*%random%
    If exist data\fights\%UID%.txt (
    goto YouLost
    )
    If Not Exist data\fights (
    md data\fights
    )
    echo %AccName% %Result% Against The %Target%.>data\fights\%UID%.txt
    echo.>>data\fights\%UID%.txt
    echo  You [%Result%] The Fight.>>data\fights\%UID%.txt
    echo  You Banished, The %Target% To The Underworld.>>data\fights\%UID%.txt
    echo.>>data\fights\%UID%.txt
    echo  Your Max Hit Was: [%Mhit%].>>data\fights\%UID%.txt
    echo  You Did [%nos%] Special Attacks.>>data\fights\%UID%.txt
    echo  Your Finishing Health Was: [%CHealth%/%MHealth%].>>data\fights\%UID%.txt
    echo.>>data\fights\%UID%.txt
    echo  Your Opponents Max Hit Was: [%OMhit%].>>data\fights\%UID%.txt
    echo  Your Opponent Did [%onos%] Special Attacks.>>data\fights\%UID%.txt
    echo  Your Opponents Finishing Health Was: [%OCHealth%/%OMHealth%].>>data\fights\%UID%.txt
    cls
    echo.
    echo  [Fight Summary]
    echo.
    echo  You [%Result%] The Fight.
    echo  The %Target% Sent You To The Underworld.
    echo.
    echo  Your Max Hit Was: [%Mhit%].
    echo  You Did [%nos%] Special Attacks.
    echo  Your Finishing Health Was: [%CHealth%/%MHealth%].
    echo.
    echo  Your Opponents Max Hit Was: [%OMhit%].
    echo  Your Opponent Did [%onos%] Special Attacks.
    echo  Your Opponents Finishing Health Was: [%OCHealth%/%OMHealth%].
    echo.
    echo.
    echo.
    echo  UID: [%UID%]
    pause >nul
    exit


    Pause >nul

    Helpmeh

      Topic Starter


      Guru

    • Roar.
    • Thanked: 123
      • Yes
      • Yes
    • Computer: Specs
    • Experience: Familiar
    • OS: Windows 8
    Re: Random
    « Reply #8 on: October 11, 2008, 08:53:22 AM »
    I'm sorry if you thought you that I wanted to copy your game. I just saw the PvComp thing and thought I could make something simmilar. Anyway I fixed a small glitch in my code. This one works(except the random is only random the first time).

    Code: [Select]
    @echo off
    if not exist mhpfile echo 100 > mhpfile
    if not exist phpfile echo 100 > phpfile
    set /a mdmg=(%Random% %%20)+1
    set /a pdmg=(%Random% %%20)+1
    set /p mhp=<mhpfile
    set /p php=<phpfile
    Echo [Monster Health] %mhp%
    Echo.
    Echo.
    Echo [Your    Health] %php%
    pause
    cls
    Echo [Monster Health] %mhp%
    Echo.
    Echo.
    Echo [Your    Health] %php%
    :attack
    Echo Attack?
    set /p att1="Y/N "
    if '%att1%'=='N' goto exit
    if '%att1%'=='n' goto exit
    if '%att1%'=='Y' goto att1
    if '%att1%'=='y' goto att1
    :att1
    cls
    Echo [Monster Health] %mhp%
    Echo [Monster Attack] %mdmg%
    Echo.
    Echo.
    Echo [Your    Health] %php%
    Echo [Your    Attack] %pdmg%
    pause
    cls
    set /a mhp=(%mhp%-%pdmg%)
    set /a php=(%php%-%mdmg%)
    Echo [Monster Health] %mhp%
    echo.
    echo.
    Echo [Your    Health] %php%
    pause
    goto attack
    :exit
    exit

    I see something now that could make a difference. I need to add/subtract random from the previous attack...
    set /a Damage=%Damage%+%random%%%%Attack%   Am I right? The 2 extra % signs are a bit confusing though.
    Where's MagicSpeed?
    Quote from: 'matt'
    He's playing a game called IRL. Great graphics, *censored* gameplay.

    Jacob



      Hopeful

      Thanked: 1
      • Experience: Expert
      • OS: Windows XP
      Re: Random
      « Reply #9 on: October 11, 2008, 08:57:19 AM »
      I'm sorry if you thought you that I wanted to copy your game. I just saw the PvComp thing and thought I could make something simmilar. Anyway I fixed a small glitch in my code. This one works(except the random is only random the first time).

      Code: [Select]
      @echo off
      if not exist mhpfile echo 100 > mhpfile
      if not exist phpfile echo 100 > phpfile
      set /a mdmg=(%Random% %%20)+1
      set /a pdmg=(%Random% %%20)+1
      set /p mhp=<mhpfile
      set /p php=<phpfile
      Echo [Monster Health] %mhp%
      Echo.
      Echo.
      Echo [Your    Health] %php%
      pause
      cls
      Echo [Monster Health] %mhp%
      Echo.
      Echo.
      Echo [Your    Health] %php%
      :attack
      Echo Attack?
      set /p att1="Y/N "
      if '%att1%'=='N' goto exit
      if '%att1%'=='n' goto exit
      if '%att1%'=='Y' goto att1
      if '%att1%'=='y' goto att1
      :att1
      cls
      Echo [Monster Health] %mhp%
      Echo [Monster Attack] %mdmg%
      Echo.
      Echo.
      Echo [Your    Health] %php%
      Echo [Your    Attack] %pdmg%
      pause
      cls
      set /a mhp=(%mhp%-%pdmg%)
      set /a php=(%php%-%mdmg%)
      Echo [Monster Health] %mhp%
      echo.
      echo.
      Echo [Your    Health] %php%
      pause
      goto attack
      :exit
      exit

      Please download here and take a look:
      http://www.computerhope.com/forum/index.php/topic,67845.0.html
      This might help you.
      As for the random I thought I had the same problem as you whilst I was making my game, until i found it was a glitch.

      I now use this for my damage:
      set /a OppDamage=%random%%%%OAttack%-29
      set /a Damage=%random%%%%Attack%-29
      that seems to do the job.

      Helpmeh

        Topic Starter


        Guru

      • Roar.
      • Thanked: 123
        • Yes
        • Yes
      • Computer: Specs
      • Experience: Familiar
      • OS: Windows 8
      Re: Random
      « Reply #10 on: October 11, 2008, 09:03:13 AM »
      I get a really wierd error in the first 2 lines when I run it.
      "Divide by zero error."
      "Divide by zero error."

      Any help?
      Where's MagicSpeed?
      Quote from: 'matt'
      He's playing a game called IRL. Great graphics, *censored* gameplay.

      Jacob



        Hopeful

        Thanked: 1
        • Experience: Expert
        • OS: Windows XP
        Re: Random
        « Reply #11 on: October 11, 2008, 09:04:17 AM »
        I get a really wierd error in the first 2 lines when I run it.
        "Divide by zero error."
        "Divide by zero error."

        Any help?

        On my game?
        or just PvComp

        Jacob



          Hopeful

          Thanked: 1
          • Experience: Expert
          • OS: Windows XP
          Re: Random
          « Reply #12 on: October 11, 2008, 09:08:28 AM »
          Your or the monsters attack level has no effect on their damage.
           (you need a function like this)
          Code: [Select]
          set /a OppDamage=%random%%%%OAttack%-29
          set /a Damage=%random%%%%Attack%-29
          Which is like you and your opponent hitting damage each time.

          You will need to change %OAttack% to your opponents attack variable (mdmg)? and you will need to change %Attack% to your attack level variable. (pdmg)?

          meanwhile, this will provide you with some inspiration:
          http://www.youtube.com/watch?v=pqJcQM0LMjw&fmt=18

          Helpmeh

            Topic Starter


            Guru

          • Roar.
          • Thanked: 123
            • Yes
            • Yes
          • Computer: Specs
          • Experience: Familiar
          • OS: Windows 8
          Re: Random
          « Reply #13 on: October 11, 2008, 09:15:43 AM »
          I just wanted it sorta plain and simple...random numbers up to 20...but now that you mention it...I should have an attack level. But you're right mdmg=monster damage and pdmg=player damage.
          Where's MagicSpeed?
          Quote from: 'matt'
          He's playing a game called IRL. Great graphics, *censored* gameplay.

          Jacob



            Hopeful

            Thanked: 1
            • Experience: Expert
            • OS: Windows XP
            Re: Random
            « Reply #14 on: October 11, 2008, 09:16:57 AM »
            I just wanted it sorta plain and simple...random numbers up to 20...but now that you mention it...I should have an attack level.

            I misunderstood, i though Monster Attack was their attack level not their damage that round.
            And on what file did you get divide by zero error?