8.27.2011

Python: assign list to all zero

我學python 一陣子了,但一直不知道如何一次assign給list同一個值,
之前都是用range()來assign給list的,查了一下google,但似乎沒相關的說明,
原來我要問的問題太基本了,後來終於發現,原來很簡單,
如果要assign給list a,10000個0,那就:

a = [0] * 10000

同理,如果要assign給list a,9999個1,那就:

a = [1] * 9999

7.12.2011

Renpy 與 python

renpy可以用'$'或'python:'來插入python的程式碼,
不過注意,不要用來'import' pyhon的library,
否則很容易造成 遊戲存檔失效,
如果要'import'一些額外的library,
請在'init python:'中加入即可。

7.09.2011

Renpy 6.12.1: How do I show a variable in the text?

要怎麼在對話的text中秀出變數,Renpy 官網提供以下三種方法:
$ food = "apple sauce"

"I would like to try some %(food)s, please."
"I would like to try some %s, please." % food
"I would like to try some " + food + ", please."
 不過,我在Renpy 6.12.1試的結果,目前只支援第一種:
"I would like to try some %(food)s, please."

其它兩種,不確定以前有沒有支援,目前看來是不行用的。

7.02.2011

Renpy 6.12.1: Drag and Drop

Renpy 6.12.1支援滑鼠托拉(Drag and Drop)的功能,
官網有範例,不過若直接複製貼上範例code,
會發現有些小錯誤:
1. 請將drag_group改成draggroup
2. 去下載圖片,裡面的圖記得改成自己圖片的名稱

修改後範例如下:

init python:

    def detective_dragged(drags, drop):

        if not drop:
            return

        store.detective = drags[0].drag_name
        store.city = drop.drag_name

        return True

screen send_detective_screen:

    # A map as background.
    add "europe.jpg"

    # A drag group ensures that the detectives and the cities.
    draggroup:

        # Our detectives.
        drag:
            drag_name "Ivy"
            child "ivy.png"
            droppable False
            dragged detective_dragged
            xpos 100 ypos 100
        drag:
            drag_name "Zack"
            child "zack.png"
            droppable False
            dragged detective_dragged
            xpos 150 ypos 100

        # The cities they can go to.
        drag:
            drag_name "London"
            child "london.png"
            draggable False
            xpos 450 ypos 140
        drag:
            drag_name "Paris"
            draggable False
            child "paris.png"
            xpos 500 ypos 280

label send_detective:
    "We need to investigate! Who should we send, and where should they go?"

    call screen send_detective_screen

    "Okay, we'll send %(detective)s to %(city)s."