Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate

# Guess the number - tiny little game

8 replies to this topic
• Members
• 224 posts
• Last active: Apr 29 2010 01:48 PM
• Joined: 20 Mar 2010
having almost zero programming experience, and getting a lot of inspiration from the community

i made my first game in scripting, and not graphically like in GAMEMAKER

i am amazed to see how RANDOM, var, x-y
command works

code=
Random, rand, 1, 50
MsgBox,4, Guess the Number Game, I have a Number between 1 and 50. Would you like to guess the number?

IfMsgBox Yes
if (num="") {
Return
}
Else {
Gosub, guess
}

guess:
if (num<rand) {
MsgBox,,Result,The number was too low.
}
else if(num>rand){
MsgBox,,Result,The number was too high.
}
else if (num=rand){
MsgBox,,Result, Correct! You guessed the number.
return
}

Gosub, guess

• Moderators
• 3165 posts
• Last active: Apr 01 2014 01:46 AM
• Joined: 07 Oct 2006
Neat. Here's a GUI version for comparison.
Gui, Add, Text,,Guess a number from 1 through 50.

Gui, Add, Edit,   wp vNum Number

Gui, Add, Button, wp Default, OK

Gui, Show,,Number Guess

return

GuiClose:

ExitApp

ButtonOK:

If !rand

Random, rand, 1, 50

Gui, Submit, NoHide

If (Num = rand) {

GuiControl,,Msg, (%Num%) Just right!

GuiControl,,Num, Guess again to start a new game.

rand = 0

return

}

If (Num < rand)

GuiControl,,Msg, (%Num%) Too low.

Else If (Num > rand)

GuiControl,,Msg, (%Num%) Too high.

GuiControl,,Num

return

• Members
• 105 posts
• Last active: Jan 24 2011 06:54 AM
• Joined: 02 Jan 2010
Wow! This brought back nostalgic feelings! In our school days we did this using GW-BASIC. Oh! the memories of golden days.

• Members
• 224 posts
• Last active: Apr 29 2010 01:48 PM
• Joined: 20 Mar 2010

Wow! This brought back nostalgic feelings! In our school days we did this using GW-BASIC. Oh! the memories of golden days.

gwbasic is so not ahk

• Members
• 105 posts
• Last active: Jan 24 2011 06:54 AM
• Joined: 02 Jan 2010

Wow! This brought back nostalgic feelings! In our school days we did this using GW-BASIC. Oh! the memories of golden days.

gwbasic is so not ahk

In fact, as far as capabilities and usefulness is concerned, GW-BASIC cannot be compared to any programming language of modern times. It is so primitive and outdated. However, in my early school days, when we were introduced to computers, we did LOGO (age 8 ) and GW-BASIC (age 9), which provided good not-so-complex introduction to logical thinking to young children then, before moving to real useful languages like C etc.. And this game was what we were taught as one of the early examples of GW-BASIC programming! I don't think anyone would even think of using GW-BASIC now. It would be a total waste of time.

• Members
• 224 posts
• Last active: Apr 29 2010 01:48 PM
• Joined: 20 Mar 2010
yeah i also did that LOGO turtle thing
but never really mastered it

ahk is awsum!

• Members
• 18 posts
• Last active: May 02 2010 10:00 PM
• Joined: 14 Apr 2010
just two tiny little improvments here for the non gui version
ive added so that it tells you what the last number you picked was
and at the end it asks you if you want a rematch! i just felt it was missing these and reopening the file was awkward, you could also make it so it keeps track of how many guesses it took you too win in a txt file
so you can see how good you are

start:
Random, rand, 1, 50
MsgBox,4, Guess the Number Game, I have a Number between 1 and 50. Would you like to guess the number?

IfMsgBox Yes
if (num="") {
Return
}
Else {
Gosub, guess
}

guess:
if (num<rand) {
MsgBox,,Result,The number was too low.
InputBox, num, Guess, Please type your next guess go higher this time your last guess was %num%
}
else if(num>rand){
MsgBox,,Result,The number was too high.
InputBox, num, Guess, Please type your next guess go lower this time your last guess was %num%
}
else if (num=rand){
MsgBox,,Result, Correct! You guessed the number. WELL DONE!!!
return
}

Gosub, guess

Msgbox, 4,, Would You Like To Play Again?
ifmsgbox yes
goto, start
else
goto, end

end:

• Members
• 40 posts
• Last active: Feb 14 2016 07:25 AM
• Joined: 08 Apr 2013

For DRAKON-AutoHotkey version which is based on jaco0646 Gui version look here: http://www.autohotke...otkey/?p=640550

• Moderators
• 237 posts
• Connoisseur of Boobs
• Last active: Jan 04 2016 11:12 PM
• Joined: 09 Oct 2012

Upgraded this a bit, just so I'd have something to play in addition to all my other little games.

This comes with defaults (I'm not sure about the actual ability to finish above lvl 9), as well as a clean interface wrapped in a function.

NumberGuess(,,,1) ; Default accepts a "level number" which ends up with Max=10^Default and Attempts=(Default+1)*3

NumberGuess(Min:=1,Max:=100,Attempts:=5,Default:="")
{	global T,Msg,Num
static rand,Mn,Mx,A,Tries:=0
(Default?(Mx:=10**Default,A:=(Default+1)*3,Mn:=1):(Mx:=Max,Mn:=Min,A:=Attempts))
Gui,NumberGuess:Default
Gui,Add,Text,,% "Guess a number from " Mn " through " Mx "."
Gui,Add,Text,wp vT Center,% A-Tries " tries left"
Gui,Show,,Number Guess
return 1

GuiEscape:
GuiClose:
Gui,%A_Gui%:Cancel
return

NumberGuessButtonOK:
Gui,NumberGuess:Default
If(!rand,Tries++)
Random,rand,%Mn%,%Mx%
Gui,Submit,NoHide
If (Num=rand||Tries=A)
{	GuiControl,,Msg,% (Num=rand?"(" Num ") Just right! Congrats!":"Sorry, the number was: " rand)
Sleep,2000
GuiControl,,Msg,% ("Guess again to start a new game.",rand:=tries:=0)
}else GuiControl,,Msg,% "(" Num ")" (Num<rand?"Too low.":"Too high.")
GuiControl,,T,% A-Tries " tries left"
GuiControl,,Num
return
}

Let me know what you think!

Utilities and Functions:

Clarifications:

Games: