Jump to content

[Solved] Updating a Globalvariable with a script


Susanoo27

Recommended Posts

Posted

I hope this is the right forum part for my question/problem.

 

I try to make my own follower and want to make it more like a kind of dating sim ( you know gain/loose friendship and/or love points). I handel this points with two global-variables.

To hold the mod as small as possible I made a script with all function I need. One function is to update this two global-variables but I think i kind of miss something because the values doesn't update.

 

My script:

 

Scriptname Relationship_Utils Extends Quest

GlobalVariable Property Kushina_Affection  Auto  
GlobalVariable Property Kushina_Friendship  Auto  

Function change(string which, string oper, float value)
	float base = 0
	if which == "friend"
		base = Kushina_Friendship.getValue()
	elseif which == "love"
		base = Kushina_Affection.getValue()
	else
		Debug.MessageBox("Bug in Function change")
	endif
        if oper == "add"
		base = base + value
	elseif oper == "remove"
		base = base - value
	elseif oper == "multi"
		base = base * value
	elseif oper == "div"
		base = base / value
	else
		Debug.MessageBox("Bug in Function change")
	endif
	if which == "friend"
		Kushina_Friendship.SetValue(base)
	elseif which == "love"
		Kushina_Affection.SetValue(base)
	endif
EndFunction 

 

 

 

 

Than in the dialog script-section I use the function like this:

 

(GetOwningQuest() as Relationship_Utils).change("friend", "add", 10)

 

 

 

I have add my script to the Quest/Script section and made sure it's property is set on both variables and also set the proberty for the code fragment to both variables. 

 

I hope somebody could tell me what I do wrong and maybe also if there is a better solution for what I try to do. 

 

Edit:

I found the solution and in case someone else get the same problem. Basiclly you need to give the function the globaleVariable as a parameter.

Here is the changed code (old code, new code):

 

My script:

 

Scriptname Relationship_Utils Extends Quest

GlobalVariable Property Kushina_Affection Auto
GlobalVariable Property Kushina_Friendship Auto

Function change(string which GlobalVariable Kushina, string oper, float value)
    float base = 0
    if which == "friend"
        base = Kushina_Friendship.getValue()
    elseif which == "love"
        base = Kushina_Affection.getValue()
    else
        Debug.MessageBox("Bug in Function change")
    endif

    float base = Kushina.GetValue()

if oper == "add"
        base = base + value
    elseif oper == "remove"
        base = base - value
    elseif oper == "multi"
        base = base * value
    elseif oper == "div"
        base = base / value
    else
        Debug.MessageBox("Bug in Function change")
    endif
    if which == "friend"
        Kushina_Friendship.SetValue(base)
    elseif which == "love"
        Kushina_Affection.SetValue(base)
    endif

    Kushina.SetValue(base)

EndFunction

 

 

 

 

Than in the dialog script-section I use the function like this:

 

(GetOwningQuest() as Relationship_Utils).change("friend" Kushina_Friendship, "add", 10)

 

 

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...