+1 vote

So I have a buy and sell system but when I press a button (sell1) it activates another button (buy4) how can I fix it?

Debug output: (USELESS DONT USE)

report
set newsfeed N/A
onupdatermkrt
-------------------------------
buy4
update
randomvarcall
currentevent0

CODE:

extends Control

onready var News = get_node("RichTextLabel2")
onready var Stockboard1 = get_node("Tickers/RichTextLabel3")
onready var Stockboard2 = get_node("Tickers/RichTextLabel4")
onready var Stockboard3 = get_node("Tickers/RichTextLabel5")
onready var Stockboard4 = get_node("Tickers/RichTextLabel6")
onready var Money = get_node("RichTextLabel7")
onready var shareamnt = get_node("RichTextLabel8")

var balanceturn = 0
var totalmoney = 500
var lastcalled = 2

onready var eventrandomizer = RandomNumberGenerator.new()
onready var eventvar = eventrandomizer.randf_range(0.00, 100.00)
onready var stockidrandomizer = RandomNumberGenerator.new()
onready var stockidvar = stockidrandomizer.randf_range(1.00, 6.00)
onready var stockgainrandomizer = RandomNumberGenerator.new()
onready var stockgainstore = stockgainrandomizer.randf_range(1.00, 53.00)

var ORANGE_HARVESTING = round(5.00)
var NORMALSOFT = round(5.00)
var LOGICPROGRAMMING = round(5.00)
var SPINFAN = round(5.00)

var ORANGE_HARVESTINGSHARES = 0
var NORMALSOFSHARES = 0 
var LOGICPROGRAMMINGSHARES = 0
var SPINFANSHARES = 0
var totalshares = 0

var sellsys = 0

var backup = 0
var backup2 = 0
var backup3 = 0
var backup4 = 0

var currentevent = 0
var income = 0
var marketevent = 0

func _ready():
    market_updater()

func backupupdate():
    print("backupupd")
    backup = ORANGE_HARVESTING
    backup2 = NORMALSOFT
    backup3 = LOGICPROGRAMMING
    backup4 = SPINFAN

func randomvar():
    print("randomvarcall")
    eventvar = round(eventrandomizer.randf_range(0.00, 100.00))
    stockidvar = round(stockidrandomizer.randf_range(1.00, 9.00))
    stockgainstore = round(stockgainrandomizer.randf_range(1.00, 53.00))



func updatefunc():
    sellsys = 0
    print("update")
    moneycalc()
    randomvar()
    event_director()

func news_director():
    print("report")
    if currentevent > 0:
        if currentevent == 1 or currentevent > 1 and currentevent < 5:
            print("set newsfeed 1")
            News.text = str("NEWS: All stocks are expected to fall")
        if currentevent == 5 or currentevent > 5:
            print("set newsfeed 2")
            News.text = str("NEWS: All stocks are expected to rise")
    else:
        print("set newsfeed N/A")
        News.text = ("NEWS: Market predictions yields no change right now")


func event_director():
    print("currentevent", currentevent)
    eventrandomizer.randomize()
    if eventvar < 5 and eventvar > 0:
        currentevent = 0
        market_update(0)
    if eventvar > 5:
        if eventvar == 10 or eventvar > 1 and eventvar < 10:
            currentevent = 1
            market_update(8)
        if eventvar < 15 and eventvar > 10:
            currentevent = 2
            market_update(12)
        if eventvar < 20 and eventvar > 15:
            currentevent = 3
            market_update(15)
        if eventvar > 20 and eventvar < 20:
            currentevent = 4
            market_update(53)
    if eventvar < 1 or eventvar > 50:
        currentevent = 5
        market_update(stockgainstore)


func market_update(marketevent):
    print("mkrtupdate")
    stockidrandomizer.randomize()
    market_price_director(marketevent, stockidvar)


func market_updater():
    news_director()
    print("onupdatermkrt")
    Stockboard1.text = str("ORHV: $", ORANGE_HARVESTING)
    Stockboard2.text = str("NOSO: $", NORMALSOFT)
    Stockboard3.text = str("LOPR: $", LOGICPROGRAMMING)
    Stockboard4.text = str("SPFA: $", SPINFAN)
    shareamnt.text = str("You own: ", totalshares, " shares")
    Money.text = str("$", totalmoney)
    lastcalled = lastcalled - 1
    print("-------------------------------")


func market_price_director(rate, stockidnum):
    print("stockid", stockidnum)
    if stockidnum == 1 or stockidnum < 2 and stockidnum > 1:
        if ORANGE_HARVESTING < rate:
            pass
        else: 
            ORANGE_HARVESTING = ORANGE_HARVESTING - rate
    if stockidnum == 2 or stockidnum < 3 and stockidnum > 1 and stockidnum > 2:
        if NORMALSOFT < rate:
            pass
        else:
            NORMALSOFT = NORMALSOFT - rate
    if stockidnum == 3 or stockidnum > 3 and stockidnum < 4:
        if LOGICPROGRAMMING < rate:
            pass
        else:
            LOGICPROGRAMMING = LOGICPROGRAMMING - rate
    if stockidnum == 4 or stockidnum > 3 and stockidnum > 4 and stockidnum < 5:
        if SPINFAN < rate:
            pass
        else:
            SPINFAN = SPINFAN - rate

    else:
        if stockidnum == 5 or stockidnum > 5 and stockidnum < 6:
            ORANGE_HARVESTING = ORANGE_HARVESTING + rate
            balanceturn = 0
        if stockidnum == 6 or stockidnum < 6  and stockidnum > 5:
            NORMALSOFT = NORMALSOFT + rate
            balanceturn = 0
        if stockidnum == 7 or stockidnum > 7 and stockidnum < 8:
            LOGICPROGRAMMING = LOGICPROGRAMMING + rate
            balanceturn = 0
        if balanceturn == 0:
            SPINFAN = SPINFAN + rate
            balanceturn = 1
        else:
            pass

    market_updater()

func incomecalc():
    var avg = 0 
    var avgdiff = 0
    var totalsub = 0 
    avg = (ORANGE_HARVESTING + NORMALSOFT + LOGICPROGRAMMING + SPINFAN) / 4
    avgdiff = (backup + backup2 + backup3 + backup4) / 4
    totalsub = avg - avgdiff
    totalmoney = totalmoney + totalsub

func moneycalc():
    totalshares = ORANGE_HARVESTINGSHARES + NORMALSOFSHARES + LOGICPROGRAMMINGSHARES + SPINFANSHARES
    incomecalc()

func _on_Button5_pressed():
    if lastcalled == 0:
        lastcalled = 2
        backupupdate()
        updatefunc()
    else: 
        updatefunc()

# END UPDATE

func _on_Button4_pressed():
    print("buy4")
    if totalmoney > SPINFAN and sellsys == 0:
        SPINFANSHARES = SPINFANSHARES + 1
        totalmoney = totalmoney - SPINFAN
    else:
        pass

func _on_Button3_pressed():
    print("buy3")
    if totalmoney > LOGICPROGRAMMING and sellsys == 0:
        LOGICPROGRAMMINGSHARES = LOGICPROGRAMMINGSHARES + 1
        totalmoney = totalmoney - LOGICPROGRAMMING
    else:
        pass

func _on_Button2_pressed():
    print("buy2")
    if totalmoney > NORMALSOFT and sellsys == 0:
        NORMALSOFSHARES = NORMALSOFSHARES + 1
        totalmoney = totalmoney - NORMALSOFT
    else:
        pass


func _on_Button1_pressed():
    print("buy1")
    if totalmoney > ORANGE_HARVESTING and sellsys == 0:
        ORANGE_HARVESTINGSHARES = ORANGE_HARVESTINGSHARES + 1
        totalmoney = totalmoney - ORANGE_HARVESTING
    else:
        pass

# END BUY

func _on_Button6_pressed():
    sellsys = 1
    print("sell4")
    if ORANGE_HARVESTING > 0:
        ORANGE_HARVESTING = ORANGE_HARVESTING - 1
        totalmoney = totalmoney + SPINFAN
    else:
        pass


func _on_Button7_pressed():
    sellsys = 1
    print("sell3")
    if NORMALSOFSHARES > 0:
        NORMALSOFSHARES = NORMALSOFSHARES - 1
        totalmoney = totalmoney + NORMALSOFT
    else:
        pass


func _on_Button8_pressed():
    sellsys = 1
    print("sell2")
    if LOGICPROGRAMMINGSHARES > 0:
        LOGICPROGRAMMINGSHARES = LOGICPROGRAMMINGSHARES - 1
        totalmoney = totalmoney + LOGICPROGRAMMING
    else: 
        pass

func _on_Button9_pressed():
    sellsys = 1
    print("sell1")
    if SPINFANSHARES > 0:
        SPINFANSHARES = SPINFANSHARES - 1 
        totalmoney = totalmoney + SPINFAN
    else:
        pass

# END SELL
asked Mar 18 in Engine by Nothing (56 points)
edited Mar 18 by Nothing

1 Answer

0 votes
Best answer

I assume you have some of the button signal wiring mixed up or mis-assigned. Select each "mixed-up" button and look at the script function that's wired to it in the Signals panel. I'd guess one or more of them isn't what you expect.

answered Mar 18 by jgodfrey (5,246 points)
selected Mar 19 by Nothing
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.