AutoHotkey的 - 用变量的整数作为索引从数组接收内容 [英] AutoHotKey - Receive content from an array using a variables' integer as the index

查看:200
本文介绍了AutoHotkey的 - 用变量的整数作为索引从数组接收内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从使用变量的整数数组索引数组获得的字符串。但它不工作。

I want to receive a string from an array using a variables' integer as the array index. But it is not working.

尝试1

; Suspended | 0 = No, 1 = Yes
global Suspended     := 0
global SuspendedMsg  := ["The script has been paused.","The script has been re-activated."]

Pause::
    Suspend
    if suspended = 0 ; If script is not suspended
    {
        TrayTip, Paused, SuspendedMsg[Suspended], 3
        Suspended++
    } else ; If it is suspended
    {
        TrayTip, Activated, SuspendedMsg[Suspended], 3
        Suspended--
    }
return

尝试#1将只显示字符串SuspendedMsg [暂停],因为我不知道在哪里设置变量指标%。即使我将它设置为 SuspendedMsg [%悬%] 它要么显示[1]或[0]

Attempt #1 will just display the string "SuspendedMsg[Suspended]" because I don't know where to set the variable indicator %. Even if I set it to SuspendedMsg[%Suspended%] it will either display [1] or [0].

尝试二

; Suspended | 0 = No, 1 = Yes
global Suspended      := 0
global SuspendedMsg   := ["The script has been paused.","The script has been re-activated."]
global SendSuspendMsg := SuspendedMsg[Suspended]

Pause::
    Suspend
    if suspended = 0 ; If script is not suspended
    {
        TrayTip, Paused, %SendSuspendMsg%, 3
        Suspended++
    } else ; If it is suspended
    {
        TrayTip, Activated, %SendSuspendMsg%, 3
        Suspended--
    }
return

尝试#2不会做,以及,它甚至不显示任何信息。我试着用了%全球SendSuspendMsg以防万一里面摆弄:= SuspendedMsg [暂停] 变量,但它不会做没有好处。任何人都关心帮助我?

Attempt #2 won't do as well, it doesn't even display any message. I tried fiddling arround with % inside the global SendSuspendMsg := SuspendedMsg[Suspended] variable but it won't do no good. Anyone care to help me out?

推荐答案

@Blauhim错过了一个重要的一点,虽然他的回答大多是正确的。首先,在创建的时候像你这样,总是一个数组索引从1开始,然后进行2等等,等等......所以你的code是有缺陷的,当你试图用你的布尔变量打电话指数为0指数不存在(更不要说你没有强迫和关于TrayTip命令前pression)。

@Blauhim missed an important point, although his answer is mostly correct. First the Index in an Array when created like you did, always starts at 1, then proceeds to 2 etc, etc... So your code was flawed when you tried to use your Boolean variable to call to an index as a 0 Index does not exist (not to mention that you didn't force and Expression on that TrayTip Command).

; Set our variable to 1 why? Because we are going to use a Logical switch below.
Suspended     := 1
; This was correct format and I left it, although I removed Global's as they are not needed
SuspendedMsg  := ["The script has been paused.","The script has been re-activated."]

Pause::
    ; Suspend toggles each time it's called
    Suspend

    ; Here we are toggling the value of our variable using !
    ; We started with a 1 so that it would be correctly
    ;Changed to a 0 for the code below.
    suspended := !suspended

    ; Nothing changed here
    if suspended = 0 ; If script is not suspended
    {
        ; In order to pass an Array or Object or Expression to a Command you Force it
        ; using the a Percent Sign with a space on either side.
        ; Also note you were trying to use your Logical True/False 0 or 1 variable to         
        ; itterate. This didn't work because Array's always start with an Index of 1. 
        ; Below I've accounted for this by simply added a 1 to your suspended so it correctly 
        ; points to the Index in our Array.
        TrayTip, Paused, % SuspendedMsg[suspended + 1], 3

    } else ; If it is suspended
    {
        TrayTip, Activated, % SuspendedMsg[suspended + 1], 3        
    }
return

这篇关于AutoHotkey的 - 用变量的整数作为索引从数组接收内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆