【问题标题】:Trying to add elements to an array after receiving an response from an API在收到 API 的响应后尝试将元素添加到数组中
【发布时间】:2022-01-21 08:47:17
【问题描述】:

所以基本上我与在线视频扑克(jacks 或更好的)API 交互,我想创建一个自动为我做出决定的机器人,api 请求工作正常,但我希望机器人做出决定为我保留/持有 initalHand 的卡片,下面是我的代码

let bodyReq = {variables:{currency:currency,amount:betAmount},query: "mutation VideoPokerBet($amount: Float!, $currency: CurrencyEnum!) {\n  videoPokerBet(amount: $amount, currency: $currency) {\n    ...CasinoBet\n    state {\n      ...CasinoGameVideoPoker\n    }\n  }\n}\n\nfragment CasinoBet on CasinoBet {\n  id\n  active\n  payoutMultiplier\n  amountMultiplier\n  amount\n  payout\n  updatedAt\n  currency\n  game\n  user {\n    id\n    name\n  }\n}\n\nfragment CasinoGameVideoPoker on CasinoGameVideoPoker {\n  playerHand {\n    suit\n    rank\n  }\n  initialHand {\n    suit\n    rank\n  }\n  handResult\n}\n"}

let bodyHeld = {variables:{identifier:identifier,held:[]},query: "mutation VideoPokerNext($held: [VideoPokerNextHeldInput!]!, $identifier: String!) {\n  videoPokerNext(held: $held, identifier: $identifier) {\n    ...CasinoBet\n    state {\n      ...CasinoGameVideoPoker\n    }\n  }\n}\n\nfragment CasinoBet on CasinoBet {\n  id\n  active\n  payoutMultiplier\n  amountMultiplier\n  amount\n  payout\n  updatedAt\n  currency\n  game\n  user {\n    id\n    name\n  }\n}\n\nfragment CasinoGameVideoPoker on CasinoGameVideoPoker {\n  playerHand {\n    suit\n    rank\n  }\n  initialHand {\n    suit\n    rank\n  }\n  handResult\n}\n"}

async function vpokerBet() {
    try{
    running.style.color = "lightgreen"
    let respData;
    while(true) {
        respData = await (await fetch(url, {
            method: "POST",
            headers: {
                "Content-Type": "application/json",
                "Accept": "application/json",
                "x-access-token": apikey,
            },
            body: JSON.stringify(
                bodyReq
            )
        })).json()
        do{
        respData = await (await fetch(url, {
            method: "POST",
            headers: {
                "Content-Type": "application/json",
                "Accept": "application/json",
                "x-access-token": apikey,
            },
            body: JSON.stringify(
                bodyHeld
            )
        })).json()}while(respData.data.videoPokerBet.active == true)

基本上假设它返回一个响应,其中 InitalHand 的数据已绘制 4 K,我想将这些卡片附加到 let bodyHeld 中的 held: [] 数组,所以我的下一个请求将保留那些 4 K ,我正在努力找出我该怎么做,任何帮助将不胜感激! , 谢谢 ! :)

【问题讨论】:

    标签: javascript arrays api append gambling


    【解决方案1】:

    我只是在我要添加的卡片中放了一个.push,下面是代码

    if (respData.data.videoPokerBet.state.initialHand[0].rank == "Q")
    {
       bodyHeld.variables.held.push(respData.data.videoPokerBet.state.initialHand[0])
    }

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-06-03
      • 1970-01-01
      • 2017-02-20
      • 2017-04-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多