## Please help fix my code :( Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
thediez1234

Im trying to get it so that a function cycles through an array and sends the text from that part of the array and when it gets to the bottom it cycles back to the top, please help, thanks you

Code: Select all

``````file=Pancake Facts.ahk]

Number := object()
Fact := object()

Fact(0) := The idea of eating pancakes on Shrove Tuesday is more than 1,000 years old!
Fact(1) := One pancake fan ran a marathon while continually tossing a pancake for three hours, two minutes and twenty seven seconds.
Fact(2) := Pancake Day, or Shrove Tuesday falls exactly 47 days before Easter Sunday.
Fact(3) := Andrei Smirnov from Russia ate a colossal 73 pancakes in one hour!
Fact(4) := Mike Cuzzacrea holds the record for the highest pancake flip at 31ft 1in.
Fact(5) := Not all countries eat pancakes on Shrove Tuesday. In Finland they eat green pea soup and pastry.
Fact(6) := The British use 52 million eggs on Pancake Day which is 22 million more than on an average day.
Fact(7) := The Guiness World Record for the most pancakes served in eight hours is 34,818.
Fact(8) := The largest pancake ever made measured 15 metres and weighed in at three tonnes.
Fact(9) := The most flips anyone has ever done with a pancake is 349 flips in two minutes.

Number := 0

{
Text(Number, Fact)
}

Func=Text(Number, Fact)
{
if Number := 10 then Number := Number - 10
Send, t
Sleep, 200
Send, (Fact(Number))
Send, {Enter}
Number := Number + 1
Return
}``````
4GForce
Posts: 553
Joined: 25 Jan 2017, 03:18
GitHub: 4GForce

Well those are fun pancakes facts !

Now some code facts
Also note that arrays in AHK start at index 1.

Good luck !
jeeswg
Posts: 6904
Joined: 19 Dec 2016, 01:58
Location: UK

### Re: Please help fix my code :(  Topic is solved

Looked nice, I guess I just wanted to see it working. It was mostly there.

A bit suspect this line, it looks more like function usage than creation:
Func=Text(Number, Fact) ;not AHK code

Code: Select all

``````;create function:
MyFunc(var1, var2)
{
MsgBox % var1 " " var2
Return var1 " " var2
}

;use function:
var3 := MyFunc(var1, var2)
``````
AutoHotkey doesn't have 'if ... then ...'. It doesn't have anything with the word 'then'.
if Number := 10 then Number := Number - 10 ;not AHK code
Have a look at ternary operator which can basically do the same thing e.g.:
(Number = 10) ? (Number := 0) : ""
or:
Number := (Number = 10) ? 0 : Number

There is also:
if (Number = 10)
Number := 0
But I also like one-liners.

Variables and Expressions
https://autohotkey.com/docs/Variables.htm#Operators

Anyway, here's the codez:

Code: Select all

``````Number := 0
Fact := object()

Fact[0] := "The idea of eating pancakes on Shrove Tuesday is more than 1,000 years old!"
Fact[1] := "One pancake fan ran a marathon while continually tossing a pancake for three hours, two minutes and twenty seven seconds."
Fact[2] := "Pancake Day, or Shrove Tuesday falls exactly 47 days before Easter Sunday."
Fact[3] := "Andrei Smirnov from Russia ate a colossal 73 pancakes in one hour!"
Fact[4] := "Mike Cuzzacrea holds the record for the highest pancake flip at 31ft 1in."
Fact[5] := "Not all countries eat pancakes on Shrove Tuesday. In Finland they eat green pea soup and pastry."
Fact[6] := "The British use 52 million eggs on Pancake Day which is 22 million more than on an average day."
Fact[7] := "The Guiness World Record for the most pancakes served in eight hours is 34,818."
Fact[8] := "The largest pancake ever made measured 15 metres and weighed in at three tonnes."
Fact[9] := "The most flips anyone has ever done with a pancake is 349 flips in two minutes."

{
Text(Number, Fact)
Number++
(Number = 10) ? (Number := 0) : ""
}

Text(Number, Fact)
{
Send, t
Sleep, 200
Send, % "{Raw}" Fact[Number]
Send, {Enter}
Return
}
``````
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA