任务没有正确设置变量?

时间:2015-07-17 23:16:43

标签: volt voltrb

在将变量传递给客户端时遇到一些问题。运行的任务是:

def getmaps
  $mapnames_current = []
  url = 'http://s3-ap-northeast-1.amazonaws.com/splatoon-data.nintendo.net/stages_info.json'
  resp = Net::HTTP.get_response(URI.parse(url))
  buffer = resp.body
  result = JSON.parse(buffer)
  result.each do |gamemode|
    gamemode['stages'].each do |stage|
      $mapnames_current << $mapnames.key(stage['id'])
    end
  end
end
在这里调用

$mapnames_current

    <div class="text-center">
      <h2>Current Maps!</h2>
      <h3>Turf War:</h3>
      <h2>{{ $mapnames_current[0] }}</h2>
      <h2>{{ $mapnames_current[1] }}</h2>
      <h3>Ranked:</h3>
      <h2>{{ $mapnames_current[2] }}</h2>
      <h2>{{ $mapnames_current[3] }}</h2>
    </div>

我不确定这里出了什么问题。不应该随处可以访问$mapnames_current变量吗?

1 个答案:

答案 0 :(得分:0)

全局变量未在客户端和服务器之间同步。客户端和服务器之间在任务中唯一传递的是任务的返回值。 (这应该是可以序列化为json(或json中的日期类型)的东西。)

这里的任务有一个很好的截屏视频:http://datamelon.io/blog/2015/creating-volt-task-objects.html