After Liu Bei's death, Zhuge Liang took on the heavy responsibility of Shu, doing everything himself, and breaking down from overwork. The handsome young man turned into an old man, which made people feel sad at first sight. When he was in Wuzhangyuan, he realized that he was dying, but Sima Yi of Cao Wei was still alive and couldn't go on in Han Shu. There were several forces in his own army, which was not harmonious. If he hadn't been in charge, the contradiction would have been provoked.
Because of this, he decided to make a plan at the end of his life to see who was unfaithful in Shu Han. So Zhuge Liang lit the seven-star lamp and declared that "if you don't die for seven days, you can live for twelve more years." Twelve years, if you really give him such a long time, why worry about not finishing the great cause of Shu Han? But on the seventh day, Wei Yan accidentally knocked over the seven-star lamp after entering the tent because he wanted to report the military situation. In the end, Zhuge Liang failed to extend his life and died in Wuzhangyuan.
Zhuge Liang didn't really set up this seven-star lamp to continue his life. If he was really that powerful, he could have continued his life long ago, and he could even help Liu Bei and others to continue their lives. Why wait until his life runs out? So all he did was find out which of them thought of him and wanted him to ascend to heaven.
Wei Yan did not hide his thoughts. He deliberately said that he would report to the military intelligence to find Zhuge Liang, and "accidentally" knocked over the seven-star lamp. Only this one thing made Zhuge Liang think that Wei Yan would rebel, and then he made a plan for Ma Dai to slay Wei Yan. This can also be regarded as spending the least cost to quell the civil strife in Shu Han before death.